Search code examples
imagepdfimagemagickpng

imagemagick cropped images to pdf: pdf maintains cropped dimensions


I have a few large pngs. I'm cropping them with convert and then creating a pdf from them.

find . -name 'test_*.png' -exec convert -crop 600x1000+400+50 {} {} \; -exec echo {} \;
convert `ls -v test_*.png` test.pdf

It all works well enough. The images are cropped fine. The pdf is generally fine. The problem is that each page of the resulting pdf has white padding which matches the pre-cropped image size.

Am I missing a step to reset the image size metadata or something?


Solution

  • I think this might be better:

    find . -name 'test_*.png'  -print -exec convert {} -crop 600x1000+400+50 +repage {} \;
    convert test_*.png test.pdf
    

    I think -print amounts more succinctly to -exec echo {} \;

    The preferred order of ImageMagick commands is:

    convert input.png ... output.png
    

    The +repage makes an image forget its previous canvas size.