We are going to see a quick list of usefull commands to edit images with the terminal.
Compress by size
First install jpegoptim with:
userk@dopamine:~$ sudo apt-get install jpegoptim
Next, suppose we have the following images in a folder:
userk@dopamine:~/images/$ du -sh *
18M background.png
230K call_to_action.jpg
Now we would like out background image to weight maximum 800Kb. Instead of opening Gimp and perform a sequence of clicks, run:
userk@dopamine:~/images/$ jpegoptim call_to_action.jpg
call_to_action.jpg 1095x730 24bit N JFIF [OK] 237089 --> 206177 bytes (13.04%), optimized.
Let us say that we need to compress the image to a specific dimension, for example 70K
userk@dopamine:~/images/$ jpegoptim call_to_action.jpg --size=70k call_to_action.jpg
call_to_action.jpg 1095x730 24bit N JFIF [OK] 237089 --> 72083 bytes (69.60%), optimized.
Resize images with image imagemagick
First install imagemagick with:
userk@dopamine:~$ sudo apt-get install imagemagick
Let us resize a random image:
userk@dopamine:~/images/$ convert call_to_action.jpg -resize 200×100! call_to_action.jpg
call_to_action.jpg 6000x1770 24bit P JFIF [OK] 593142 --> 593142 bytes (0.00%), skipped.
Convert from png jpg
Let us convert a png image called imageIn in a jpg file. We will rename it imageOut.
userk@dopamine:~/images/$ convert imageIn.png imageOut.jpg
Convert and resize
We will use imagmagick for this. Just run this command for your input image:
userk@dopamine:~/images/$ convert imageIn.png -quality 70 imageOut.jpg
Rotate a bunch of images by X degrees
Last but not least, let us say we want to rotate a image 90 degree
userk@dopamine:~/images/$ convert imageIn.png -rotate 90 imageOut.jpg
Create a single pdf from multiple images, pdf, png or jpg files
Let’s say you have images and pdf files which you want to convert into a single pdf file. But how do we create such file?
Easy! Just call convert with all the images you want to unify and specify the output filename.
userk@dopamine:~/images/$ convert image1.jpg image2.png PDFfile.pdf outputFileName.pdf