Skip to content

Instantly share code, notes, and snippets.

@mijoharas
Last active September 18, 2021 04:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mijoharas/7447237 to your computer and use it in GitHub Desktop.
Save mijoharas/7447237 to your computer and use it in GitHub Desktop.
imagemagick
# convert with transparency
convert screenshot2.tiff -transparent '#112332' screenshot2.png
# convert with gaussian blur
convert forest.jpg -gaussian-blur 0x18 forest_blur.jpg
#shave 4 pixels off the top and bottom
convert screenshot4.png -shave 0x4 screenshot4_crop.png
# crop to square 422x422 with 0x0 offset
convert mike_gravatar.jpeg -crop 422x422+0+0 mike_gravatar_square.jpeg
# give circular alpha channel around it NOTE this is for a 422x422 image (note the 211x211)
convert mike_gravatar_square.jpeg \( +clone -threshold -1 -negate -fill white -draw "circle 211,211,211,0" \) -alpha off -compose copy_opacity -composite mike_gravatar_circle.png
# lighten an image by some amount (gamma less than one darkens, greater lightens)
convert mike_gravatar_circle.png -gamma 2 mike_gravatar_circle_light_2.png
# crop to square that is 100x100 http://superuser.com/questions/275476/square-thumbnails-with-imagemagick-convert
convert -define jpeg:size=200x200 original.jpeg -thumbnail 100x100^ -gravity center -extent 100x100 thumbnail.jpeg
# crop bottom 8px of image
convert thumbnail.jpeg -crop -0-8 thumbnail_crop.jpeg
# extract the alpha channel of an image
convert swirl_120.png -alpha extract extracted_alpha.png
# copy an alpha channel mask onto another image
convert image.png \( alpha_mask.png -colorspace gray -alpha off \) -compose CopyOpacity -composite output.png
# This doesn't work correctly (no idea why)
#!/bin/bash
if [ "$1" != "" ]; then
convert $1 -resize 128x128 favicon-128.png
convert $1 -resize 16x16 favicon-16.png
convert $1 -resize 32x32 favicon-32.png
convert $1 -resize 64x64 favicon-64.png
convert favicon-16.png favicon-32.png favicon-64.png favicon-128.png -colors 256 favicon.ico
fi
convert logo_gts.png logo_gts.ico
convert logo_gts.ico -resize 16x16 favicon-16.ico
convert logo_gts.ico -resize 32x32 favicon-32.ico
convert logo_gts.ico -resize 48x48 favicon-48.ico
convert logo_gts.ico -resize 64x64 favicon-64.ico
convert logo_gts.ico -resize 256x256 favicon-256.ico
convert logo_gts.ico -resize 128x128 favicon-128.ico
convert favicon-16.ico favicon-32.ico favicon-64.ico favicon-128.ico favicon-256.ico favicon.ico
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment