Skip to content

Instantly share code, notes, and snippets.

@marten-cz
Created July 12, 2014 09:59
Show Gist options
  • Save marten-cz/ad1f65e1bd4c0de7f9bf to your computer and use it in GitHub Desktop.
Save marten-cz/ad1f65e1bd4c0de7f9bf to your computer and use it in GitHub Desktop.
Convert images into PDF with resize and optimization

Solution requires ImageMagick

Convert files into JPG and rotate for file in *.bmp; do convert -resize 50% -rotate 90 "$file" rot/"$file".jpg; done

Convert images and optimize them as text pages for img in *.bmp; do mogrify -normalize -level 10%,90% -sharpen 0x1 -rotate 90 $img rot/"$img".jpg; done

Convert with better filename handling for file in *.bmp; do filet=basename $file .bmp; convert -rotate 90 -resize 50% "$file" rot/"printf %04d $filet".jpg; done

Add leading zeros for a in [0-9]*.jpg; do mv $a printf %04d.%s ${a%.*} ${a##*.}; done

Convert all images into PDF convert rot/*.jpg -adjoin output.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment