IT IS ALL B3

where he writes his head up.

B3 Uses ImageMagick to Optimise Images 19 Jan 2018

This is not a story about B3, The Owner of this blog. This is just a story about how a human being uses ImageMagick to optimise images. This human being is happen to be B3, The Owner of this blog.

Well, in order to optimise all the images before publish them to the interweb, a hand some fat guy named B3 dug the interweb for a solution. As a fan of cli, he tended to look for a solution which is cli-friendly. Because he is a lazy guy, that’s why he is fat you know, he decided to go with the first result he found. It was Efficient Image Resizing With ImageMagick. And he made it.

His workflow was simple:

Step 1

Install imagemagick: brew install imagemagick

Step 2

Add the function below to .function file. Yes, handsome B3 loves .dotfiles

# magikalimage $input_path $output_path $output_width
# original idea: https://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/
function magikalimage() {
	input_path="$1";
	output_path="$2";
	output_width="$3";
	
	# convert to jpg no matter what it is
	# mkdir -p /tmp/magikalimage/original
	# cp "$input_path" /tmp/magikalimages/original && cd /tmp/magikalimage/original

	if [ -n "$3" ]; then
		mogrify -path "$output_path" -filter Triangle -define filter:support=2 -thumbnail "$output_width" -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace plane -colorspace sRGB -format jpg "$input_path"
	else
		mogrify -path "$output_path" -filter Triangle -define filter:support=2 -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace plane -colorspace sRGB -format jpg "$input_path"
	fi
}

Notes

  1. B3 prefer jpeg format so he added -format jpg
  2. B3 prefer jped progressive so he changed from -interlace none to -interlace plane
  3. B3 doesn’t prefer resizing that’s why the function has the if condition.

That’s it. Story ends.

© 2018. All rights reserved. Served by Jekyll on Gitlab Pages. SSL by Let's Encrypt. Made with ♥ using Tufte CSS