Difference between revisions of "Convert"

From Notes_Wiki
m
m
Line 1: Line 1:
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Image processing tools]] > [[Convert]]
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Image processing tools]] > [[Convert]]


=Convert from one format to another=
We can use convert to convert from one image format to another. For example to convert '<tt>test.png</tt>' to '<tt>test.jpg</tt>' we can use:
We can use convert to convert from one image format to another. For example to convert '<tt>test.png</tt>' to '<tt>test.jpg</tt>' we can use:
<pre>
<pre>
Line 10: Line 11:




==Resizing image==
=Resizing image=


To resize an image using convert use:
To resize an image using convert use:
Line 19: Line 20:




==Cropping image==
=Cropping image=
To crop an image using convert use:
To crop an image using convert use:
<pre>
<pre>
Line 27: Line 28:




==Convert pdf to jpg with good resolution==
=Convert pdf to jpg with good resolution=
By default using '<tt>convert &lt;source.pdf&gt; &lt;destination.jpg&gt;</tt>' does not gives a good resolution jpg image.  To get better resolution use:
By default using '<tt>convert &lt;source.pdf&gt; &lt;destination.jpg&gt;</tt>' does not gives a good resolution jpg image.  To get better resolution use:
<pre>
<pre>
Line 34: Line 35:
Learned from http://xmodulo.com/convert-pdf-files-to-jpg-format-on-linux.html
Learned from http://xmodulo.com/convert-pdf-files-to-jpg-format-on-linux.html


Also see [[CentOS 7.x convert from ImageMagick]]




Line 48: Line 50:
*Note: Use at least 300 dpi during scanning to create a good usable ebook.
*Note: Use at least 300 dpi during scanning to create a good usable ebook.


You can also consider using https://smallpdf.com/jpg-to-pdf to achieve the same from web browser.  After creating the pdf in browser use the right side menu compress option to also compress it.
'''The created pdf is typically very big.  You should compress it further as explained at [[Pdftk]]'''





Revision as of 03:31, 12 September 2023

Home > CentOS > CentOS 6.x > Image processing tools > Convert

Convert from one format to another

We can use convert to convert from one image format to another. For example to convert 'test.png' to 'test.jpg' we can use:

convert test.png test.jpg

Convert command also supports many options. One can use 'convert -help' to see brief description and supported options. For details we need to use ImageMagick package documentation.


Resizing image

To resize an image using convert use:

convert src.jpg -resize 10x10 dst.jpg

where 10x10 is the desired size of destination image. The resulting image is automatically centered to maintain aspect ratio.


Cropping image

To crop an image using convert use:

convert src.jpg -crop 22x38+10+12 dst.jpg

Here, 22x38 is the size of the resulting image after crop. +10 is the X offset even - can be used to indicate coordinates from other direction. Similarly +12 is the Y offset. Here also instead of +, - can be used to indicate counting in opposite direction.


Convert pdf to jpg with good resolution

By default using 'convert <source.pdf> <destination.jpg>' does not gives a good resolution jpg image. To get better resolution use:

convert -density 300 source.pdf destination.jpg

Learned from http://xmodulo.com/convert-pdf-files-to-jpg-format-on-linux.html

Also see CentOS 7.x convert from ImageMagick


Creating ebook from scanned files

We can create 'pdf' ebook from scanned files with the help of convert which is part of ImageMagick package using following steps:

  1. First all the pages of book can be scanned in 'png' format with image names corresponding to page number like 'page001.png', 'page002.png' and so on.
  2. Edit all 'png' pages and remove the extra part of image which is not useful
  3. Use below command to create pdf which has pages in right order as per image file name
    convert *.png ebook.pdf
  • Note: Use at least 300 dpi during scanning to create a good usable ebook.

You can also consider using https://smallpdf.com/jpg-to-pdf to achieve the same from web browser. After creating the pdf in browser use the right side menu compress option to also compress it.

The created pdf is typically very big. You should compress it further as explained at Pdftk


Converting train tickets to pdf format

Do not use this technique as tickets created do not have good resolution and are not useful

Using print to file and then pdf format from IRCTC using Mozilla Firefox in Linux leads to corrupted pdf which will print all black color instead of ticket details. One can verify whether pdf is printable or not by opening it in kpdf and using print preview.

To make proper pdf file:

  1. Use 'Print to file' option and choose postscript.
  2. Save file as 'ticket.ps'.
  3. Now use command 'convert ticket.ps ticket.bmp' to convert ticket to bitmap format. This will create two bmp files 'ticket-00.bmp' and 'ticket-1.bmp' containg first and second page of ticket.
  4. Delete file 'ticket-1.bmp'.
  5. Open file 'ticket-0.bmp' with Kolourpaint or GIMP and remove the advertizement. Save the file as 'ticket-0.bmp'. Note that we are using bmp format and not png/jpg etc. and png/jpg are not lossless formats.
  6. Now use 'convert ticket-0.bmp ticket.pdf' to get proper pdf file without ads which can be printed without any problem.


Home > CentOS > CentOS 6.x > Image processing tools > Convert