cropping, resizing and making images transparent

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
DrPL
Posts: 3
Joined: 2011-03-06T06:29:16-07:00
Authentication code: 8675308

cropping, resizing and making images transparent

Post by DrPL »

Hi,
This is my first post, please be kind ;)

I'm experimenting with the imagemagick convert and mogrify commands. I have a lot of png images that I would like to:
set "black" to being transparent
crop the image so that it is 60x108+124+40
and then resize to 25% of the original size.

I've tried the command: mogrify *.png -alpha set -resize 25% -transparent black -crop 60x108+124+40
but other than change the image size from 26.8 kb to 17.1 kb, it doesn't seem to do anything.
Even when I re-order the commands into the sequence I'd like them carried out:
mogrify *.png -alpha set -transparent black -crop 60x108+124+40 -resize 25%
- nothing seems to happen.

Can anyone help?

Many thanks!

Best wishes

Paul
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: cropping, resizing and making images transparent

Post by Bonzo »

Try this:

Code: Select all

mogrify -fuzz 1% -transparent black -crop 60x108+124+40 -resize 25% *.png
You might want to use a small amount of Fuzz and do not forget the original will be overwritten!

If it does not work can you post a sample image ?
DrPL
Posts: 3
Joined: 2011-03-06T06:29:16-07:00
Authentication code: 8675308

Re: cropping, resizing and making images transparent

Post by DrPL »

Hi,
Looks great! When I open up File Browser, or Image Viewer, the image has been cropped as planned. I can't really tell if the black + fuzz has been made transparent. When I open up gimp to have a look, I get a message saying that the "PNG file specifies an offset that causes the layer to be positioned outside the image." Since the original image is 320 x 240 pixels (and yes, I did back up all the originals!), I am a bit mystified at this...

Thanks!

Paul
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: cropping, resizing and making images transparent

Post by Bonzo »

Add a +repage

Code: Select all

mogrify -fuzz 1% -transparent black -crop 60x108+124+40 -resize 25% +repage *.png
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: cropping, resizing and making images transparent

Post by Bonzo »

My tests opened OK in Gimp but the image was not on the background.
Use +repage to completely remove/reset the virtual canvas meta-data from the images.
All the options are listed here:
http://www.imagemagick.org/script/comma ... ptions.php
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: cropping, resizing and making images transparent

Post by fmw42 »

perhaps the input png files already have a virtual canvas. so try putting another +repage right after mogrify to remove it from the input image before the rest of the processing and keep the one after the crop at the end to remove the virtual canvas left by the crop. I don't know if this will help, but it is easy to try.

also what version of IM are you using? PNG processing has been under continual change and improvement over the last number of releases. So you might try upgrading to the very latest version of IM

Good reading for new users is at:
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/Usage/reference.html
DrPL
Posts: 3
Joined: 2011-03-06T06:29:16-07:00
Authentication code: 8675308

Re: cropping, resizing and making images transparent

Post by DrPL »

Bonzo wrote:Add a +repage

Code: Select all

mogrify -fuzz 1% -transparent black -crop 60x108+124+40 -resize 25% +repage *.png
It worked beautifully, many thanks!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: cropping, resizing and making images transparent

Post by anthony »

DrPL wrote:I've tried the command: mogrify *.png -alpha set -resize 25% -transparent black -crop 60x108+124+40
but other than change the image size from 26.8 kb to 17.1 kb, it doesn't seem to do anything.
Even when I re-order the commands into the sequence I'd like them carried out:
mogrify *.png -alpha set -transparent black -crop 60x108+124+40 -resize 25%
- nothing seems to happen.
Add a +repage afetr the -crop before the resize.
Also out the images at the end (for mogrify)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply