Skip to content

Commit

Permalink
Documentation: Updates for Image class and API.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamie-lemon committed Dec 16, 2024
1 parent a161407 commit 3816739
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 1 deletion.
132 changes: 132 additions & 0 deletions docs/classes/Image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,138 @@ Image
let image = new mupdfjs.Image(fs.readFileSync("logo.png"))
|instance_method_tag|

.. method:: getWidth()

Get the image width in pixels.

:return: `number`.

|example_tag|

.. code-block:: javascript
var width = image.getWidth();
.. method:: getHeight()

Get the image height in pixels.

:return: `number`.

|example_tag|

.. code-block:: javascript
var height = image.getHeight();
.. method:: getXResolution()

Returns the x resolution for the `Image` in dots per inch.

:return: `number`.

|example_tag|

.. code-block:: javascript
var xRes = image.getXResolution();
.. method:: getYResolution()

Returns the y resolution for the `Image` in dots per inch.

:return: `number`.

|example_tag|

.. code-block:: javascript
var yRes = image.getYResolution();
.. method:: getColorSpace()

Returns the :doc:`ColorSpace` for the `Image`.

:return: :doc:`ColorSpace`.

|example_tag|

.. code-block:: javascript
var cs = image.getColorSpace();
.. method:: getNumberOfComponents()

Number of colors; plus one if an alpha channel is present.

:return: `number`.

|example_tag|

.. code-block:: javascript
var num = image.getNumberOfComponents();
.. method:: getBitsPerComponent()

Returns the number of bits per component.

:return: `number`.

|example_tag|

.. code-block:: javascript
var bits = image.getBitsPerComponent();
.. method:: getImageMask()

Returns *true* if this image is an image mask.

:return: `boolean`.

|example_tag|

.. code-block:: javascript
var hasMask = image.getImageMask();
.. method:: getMask()

Get another `Image` used as a mask for this one.

:return: `Image` (or `null`).

|example_tag|

.. code-block:: javascript
var mask = image.getMask();
.. method:: toPixmap()

Create a :doc:`Pixmap` from the image.

:return: :doc:`Pixmap`.


|example_tag|

.. code-block:: javascript
var pixmap = image.toPixmap();
.. include:: footer.rst
.. include:: ../footer.rst

Expand Down
25 changes: 24 additions & 1 deletion docs/how-to-guide/node/document/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,33 @@ To get the images for an entire document use the :meth:`getImages` method on eac
let i = 0
while (i < document.countPages()) {
const page = new mupdfjs.PDFPage(document, i)
let images = page.getImages()
let imageStack = page.getImages()
i++
}
The following example would extract all the images from a document and save them as individual files:

.. code-block:: javascript
let i = 0
while (i < document.countPages()) {
const page = new mupdfjs.PDFPage(document, i)
let imageStack = page.getImages()
for (var j in imageStack) {
var image = imageStack[j].image;
var pixmap = image.toPixmap();
let raster = pixmap.asJPEG(80);
fs.writeFileSync('page-'+i+'-image-'+j+'.jpg', raster);
}
i++
}
Extracting Document Annotations
-----------------------------------

Expand Down
14 changes: 14 additions & 0 deletions docs/how-to-guide/node/page/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ To get the images for a page we can use the :meth:`getImages` method as follows:
This returns an array of objects which includes the image (:doc:`../../../classes/Image`) along with the bounding box and matrix transform.


The following example would extract all the images from a page and save them as individual files:

.. code-block:: javascript
var imageStack = page.getImages()
for (var i in imageStack) {
var image = imageStack[i].image;
var pixmap = image.toPixmap();
let raster = pixmap.asJPEG(80);
fs.writeFileSync('image-'+i+'.jpg', raster);
}
Extracting Page Annotations
-----------------------------------

Expand Down

0 comments on commit 3816739

Please sign in to comment.