Different page sizes after conversion of png to pdf with imagemagic

46 Views Asked by At

I have a number of pngs with the same size:

$ identify *.png
0010.png PNG 770x1270 770x1270+0+0 8-bit sRGB 2.27474MiB 0.000u 0:00.000
0011.png PNG 770x1270 770x1270+0+0 8-bit sRGB 2.32027MiB 0.000u 0:00.000
0020.png PNG 770x1270 770x1270+0+0 8-bit sRGB 466583B 0.000u 0:00.000
0021.png PNG 770x1270 770x1270+0+0 8-bit sRGB 442099B 0.000u 0:00.000
0030.png PNG 770x1270 770x1270+0+0 8-bit sRGB 875894B 0.000u 0:00.000
0031.png PNG 770x1270 770x1270+0+0 8-bit sRGB 438896B 0.000u 0:00.000
0040.png PNG 770x1270 770x1270+0+0 8-bit sRGB 876244B 0.000u 0:00.000
...

I would like to convert them to a pdf with imagemagick. I do:

convert *.png -resize 770x1270 merged_70x120.pdf 

(I also tried dropping the -resize option). However, the final pages are of different, unpredictable sizes:

$ identify merged_70x120.pdf
merged_70x120.pdf[0] PDF 432x756 432x756+0+0 16-bit sRGB 3343B 0.060u 0:00.058
merged_70x120.pdf[1] PDF 432x756 432x756+0+0 16-bit sRGB 3315B 0.060u 0:00.059
merged_70x120.pdf[2] PDF 936x1512 936x1512+0+0 16-bit sRGB 4427B 0.060u 0:00.059
merged_70x120.pdf[3] PDF 288x468 288x468+0+0 16-bit sRGB 2770B 0.060u 0:00.058
merged_70x120.pdf[4] PDF 936x1512 936x1512+0+0 16-bit sRGB 5467B 0.060u 0:00.058
merged_70x120.pdf[5] PDF 288x468 288x468+0+0 16-bit sRGB 2743B 0.060u 0:00.058

what am I doing wrong?

1

There are 1 best solutions below

0
sygi On

Apart from the pixel size (some of) the pngs have encoded properties "Print size" and "Units". One can find them by calling identify -verbose:

  Print size: 15.8273x26.3978
  Units: PixelsPerCentimeter

Knowing that, I was able to fix these attributes by passing -density dpi -units pixelsperinch to convert.