7

I'm converting a bunch of pdf vector figures to png files.

for f in *.pdf
   do convert -trim ${f} "${f}.png"
done
rename 's/\.pdf//' *.png

But the dimension of the pictures are too small.

The doc of convert tells a -size width height option but I cannot specify a unique size for all pictures. Any other ways?

13

Use the -density option to define how many pixels you want per inch; the default is -density 72.

Also, since you're using Bash, you can directly manipulate the file name in the loop:

for src in *.pdf ; do
    convert -trim "${src}" "${src%.*}.png"
done

without having to do a post-rename. ${src%.*} in Bash evaluates to the contents of src, but with everything following a final . removed. (If src does not contain ., ${src%.*} evaluates to the same as $src.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.