Difference between revisions of "Convert"

From Notes_Wiki
m
m
Line 1: Line 1:
<yambe:breadcrumb>Image processing tools</yambe:breadcrumb>
<yambe:breadcrumb self="Convert">Image processing tools|Image processing tools</yambe:breadcrumb>
=convert=
=convert=


Line 69: Line 69:




<yambe:breadcrumb>Image processing tools</yambe:breadcrumb>
<yambe:breadcrumb self="Convert">Image processing tools|Image processing tools</yambe:breadcrumb>

Revision as of 10:51, 9 September 2018

<yambe:breadcrumb self="Convert">Image processing tools|Image processing tools</yambe:breadcrumb>

convert

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


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.


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.



<yambe:breadcrumb self="Convert">Image processing tools|Image processing tools</yambe:breadcrumb>