Skip to content

Instantly share code, notes, and snippets.

@iCreateJB
Forked from anonymous/thumbnail.rb
Last active December 13, 2015 21:48
Show Gist options
  • Save iCreateJB/4979468 to your computer and use it in GitHub Desktop.
Save iCreateJB/4979468 to your computer and use it in GitHub Desktop.
# Create Image Mask ( circle.png )
# convert -size 168x168 xc: -transparent white -fill blue -draw 'circle 84,84 24,24' circle.png
# System command.
# convert original.image.png -resize '168x168^' -gravity center -crop '168x168+0+0' original.resize.png;
# convert -size 168x168 xc: -fill original.resize.png -draw 'circle 85,80 25,25' circle.png
# Leaves the image offset but centered.
# image = Magick::Image.read('original.image.png').first
# image.resize_to_fill(168,168,'center')
# image.write 'original.resize.png'
# image.destroy!
# `convert -size 168x168 xc: -fill original.resize.png -draw 'circle 85,80 25,25' thumbnail.png`
@mask = Magick::Image.read('circle.png').first
@destination = Magick::Image.read('original.image.png').first
@source = Magick::Image.new 168,168
@destination.resize_to_fill!(168,168)
@destination = @destination.add_compose_mask(@mask)
@result = @destination.composite(@source, Magick::CenterGravity, Magick::OverCompositeOp)
@result = @result.add_compose_mask(@mask)
@result = @result.blur_image(0,0.25)
@result.write 'original.resize.png'
@result.destroy!
@shannonrush
Copy link

@shannonrush
Copy link

@iCreateJB
Copy link
Author

Created a mask via:
convert -size 168x168 xc: -fill blue -draw 'circle 85,80 25,25' circle.png
Then took the original image as the argument, resized it and placed the mask over it. It seems to have created the desired effect that I was after. Do you see any issues with it?

@shannonrush
Copy link

If that produces what you want I say ship it :)

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