Difference between revisions of "Convert"
m |
m |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[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 11: | Line 11: | ||
=Resizing image= | |||
==Creating ebook from scanned files | To resize an image using convert use: | ||
<pre> | |||
convert src.jpg -resize 10x10 dst.jpg | |||
</pre> | |||
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: | |||
<pre> | |||
convert src.jpg -crop 22x38+10+12 dst.jpg | |||
</pre> | |||
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 '<tt>convert <source.pdf> <destination.jpg></tt>' does not gives a good resolution jpg image. To get better resolution use: | |||
<pre> | |||
convert -density 300 source.pdf destination.jpg | |||
</pre> | |||
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: | We can create 'pdf' ebook from scanned files with the help of convert which is part of ImageMagick package using following steps: | ||
Line 24: | 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]]''' | |||
=Converting train tickets to pdf format= | |||
'''Do not use this technique as tickets created do not have good resolution and are not useful''' | '''Do not use this technique as tickets created do not have good resolution and are not useful''' | ||
Line 40: | Line 70: | ||
=Convert pdf to png ensuring white background and not trasparent especially for boarding pass= | |||
Sometimes boarding pass pdf get converted to png with transparent background. To convert using white background instead use: | |||
<pre> | |||
To | convert -density 300 input.pdf -background white -alpha remove -alpha off +adjoin output-%03d.png | ||
<pre> | |||
convert | |||
</pre> | </pre> | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Image processing tools]] > [[Convert]] |
Latest revision as of 03:46, 19 October 2024
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:
- 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.
- Edit all 'png' pages and remove the extra part of image which is not useful
- 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:
- Use 'Print to file' option and choose postscript.
- Save file as 'ticket.ps'.
- 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.
- Delete file 'ticket-1.bmp'.
- 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.
- Now use 'convert ticket-0.bmp ticket.pdf' to get proper pdf file without ads which can be printed without any problem.
Convert pdf to png ensuring white background and not trasparent especially for boarding pass
Sometimes boarding pass pdf get converted to png with transparent background. To convert using white background instead use:
convert -density 300 input.pdf -background white -alpha remove -alpha off +adjoin output-%03d.png
Home > CentOS > CentOS 6.x > Image processing tools > Convert