Archive

Posts Tagged ‘imagemagick’

How to append images vertically?

February 26, 2019 Leave a comment

Problem
With youtube-dl I downloaded all the videos of a YouTube playlist. I also wanted to have a screenshot with all the videos of the playlist that contains the thumbnails, the titles, etc. As the playlist contained many videos and thus they didn’t fit on one page, I took several screenshots. For example, 01.png contained videos from 1 to 9, 02.png contained videos from 10 to 18, etc.
However, instead of several screenshots, I wanted just one long screenshot with everything. How to concatenate images vertically?

Solution
Using convert from ImageMagick:

convert -append 1.png 2.png full.png

This tip is from here.

Categories: bash Tags: , ,

[manjaro] convert refuses to produce PDFs

January 10, 2019 Leave a comment

Problem
Under Manjaro, I wanted to create a PDF from some JPG files. However, convert dropped an error:

$ convert *.jpg out.pdf
convert: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.

Solution
Edit the file /etc/ImageMagick-7/policy.xml and find the following line:

<policy domain="coder" rights="none" pattern="{PS,PS2,PS3,EPS,PDF,XPS}" />

Put it between comments (<!-- and -->) and everything is good again.

I found this solution here.

Categories: bash, linux Tags: , , ,

resize an image to a given width by keeping the aspect ratio

Problem
You want to resize an image to a given width but you want to keep the width/height ratio of the image.

Solution

convert -resize 200 big.jpg small.jpg

Here the new width will be 200 pixels.

Categories: bash Tags: , ,

animated GIFs

September 3, 2013 Leave a comment

Extract images from a GIF:

convert animated.gif frames%03d.png 

More info here.

Merge images into an animated GIF:

convert -delay 20 -loop 0 *.png result.gif

More info here.

Categories: bash Tags: , ,

Resize .tif file and convert to .jpg

November 7, 2011 Leave a comment

Use case
In the lab we have a photocopier that can scan too. Quite cool, you can precise your email address and it sends you the scanned page in .tif format.

However, pages must be scanned one by one and each of them is sent as a separate .tif file. Each .tif file is around 2.8 MB large with a resolution of 4900 x 7000 pixels. How to resize them and convert them to .jpg files? Gimp is one way but could we solve it in command-line?

Solution
Put the .tif files in a folder and create a subfolder called “out”. This way the output won’t be mixed with the input.

for i in *.tif; do echo $i; convert $i -resize 24% out/`basename $i .tif`.jpg; done

Each .tif is made smaller (width around 1200 pixels) and converted to .jpg.

As a final touch, convert the JPGs to a PDF file.

cd out
convert *.jpg doc.pdf

Question
Does anyone know how to to resize an image the following way: let width be 1200 pixels and keep the aspect ratio? Above the 24% was the result of a manual computation…

Answer: just use “convert -resize 1200 in.tif out.jpg“. The output will have width=1200 pixels with the same ratio as the input image. (Thanks Yves for the tip.)

Convert JPGs to PDF

November 2, 2010 Leave a comment

Problem

You have some JPG files and you want to combine them in a single PDF.

Solution

convert  *.jpg  out.pdf

The program convert is part of the imagemagick package.

Notes

The program convert is very powerful. It can convert files from/to almost all kinds of formats. Check out its man page. Official home page is here.

Categories: bash Tags: , , ,