Resize -> Crop -> Image Mask -> Merge Layers

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
kiwijunglist
Posts: 14
Joined: 2012-10-15T20:41:33-07:00
Authentication code: 67789

Resize -> Crop -> Image Mask -> Merge Layers

Post by kiwijunglist »

Hi

I'm trying to use imagemagick for auto creating missing disc images from a movie poster for mediaportal (open source home theatre pc software). I'm hoping some one can help me with the commands I need to use.

Start with poster.jpg which is a rectangular image and can be any size.

Step 1a - Centre crop into a square
Step 1b - Resize to 1000 x 1000

Step 2 - Apply a transparency mask

Step 3 - Overlay a semi transparent image on top

Save final image as png with transparency

Image

Link to poster.jpg/transperncy masks etc on photobucket

Link to .zip file with all images

Any help will be appreciated. I'm trying to do this myself but I'm struggling, hopefully this is a relatively simple task for most people and someone can chime in with the steps I need to do :D

Thanks!!! <3
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by fmw42 »

try this (unix commands)


convert poster.jpg -gravity center -crop 1000x1000+0+0 +repage \
dvdoverlay.png -compose over -composite \
transparency_mask.png -alpha off -compose copy_opacity -composite result.png

if on windows replace line continuation \ with ^

see
http://www.imagemagick.org/Usage/crop/
http://www.imagemagick.org/Usage/compose/
kiwijunglist
Posts: 14
Joined: 2012-10-15T20:41:33-07:00
Authentication code: 67789

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by kiwijunglist »

THANKS!

That is 95% there

I actually want to apply the mask before the overlay, I might be able to figure this out myself (hopefully) :D

EDIT:

convert poster.jpg -gravity center -crop 1000x1000+0+0 +repage ^ transparency_mask.png -alpha off -compose copy_opacity -composite dvdoverlay.png -compose over -composite ^ result.png

It works, THANK YOU x 1000 ! <3 <3 you saved me many hours of work :D
Last edited by kiwijunglist on 2012-10-15T22:01:42-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by fmw42 »

kiwijunglist wrote:THANKS!

That is 95% there

I actually want to apply the mask before the overlay

Why if this gets the result you want?
kiwijunglist
Posts: 14
Joined: 2012-10-15T20:41:33-07:00
Authentication code: 67789

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by kiwijunglist »

thanks, i switched the order of the commands (as above edited post) and i got the result i wanted :D

(There was some shadowing outside the dvdoverlay image that was cut off by the mask, if you applied the mask first)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by fmw42 »

kiwijunglist wrote:thanks, i switched the order of the commands (as above edited post) and i got the result i wanted :D

(There was some shadowing outside the dvdoverlay image that was cut off by the mask, if you applied the mask first)

OK. Glad you solved it.
kiwijunglist
Posts: 14
Joined: 2012-10-15T20:41:33-07:00
Authentication code: 67789

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by kiwijunglist »

There is a small problem with the resize / crop in the first part of the command

convert poster.jpg -gravity center -crop 1000x1000+0+0 +repage result.jpg

What seems to be happening is it is croping a 1000x1000 centre part of the image, but what I really want is

Resize the width to 1000 pixels while maintaining the aspect ratio, and then center crop to 1000x1000 discarding part of the top + bottom of the image

see below

Image

I'll try figure it out using those links you gave me
kiwijunglist
Posts: 14
Joined: 2012-10-15T20:41:33-07:00
Authentication code: 67789

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by kiwijunglist »

Unfortunately I wasn't able to figure out the code to do what I wanted...

however I figured out a cheat

Since all the movie posters have an aspect ratio of 0.667 If I resize to 1500x1500 then the width will be exactly 1000 pixels

convert poster.jpg -resize 1500x1500 ^ -gravity center -crop 1000x1000+0+0 +repage result.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by fmw42 »

kiwijunglist wrote:Unfortunately I wasn't able to figure out the code to do what I wanted...

however I figured out a cheat

Since all the movie posters have an aspect ratio of 0.667 If I resize to 1500x1500 then the width will be exactly 1000 pixels

convert poster.jpg -resize 1500x1500 ^ -gravity center -crop 1000x1000+0+0 +repage result.jpg

convert poster.jpg -resize 1500x1500 ^ -gravity center -crop 1000x1000+0+0 +repage result.jpg

is exactly the correct command
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by anthony »

You want to not only crop the image but resize it too.
See thumbnails. Cut thumbnail to fit...
http://www.imagemagick.org/Usage/thumbnails/#cut

The trick here is to use a special flag for the resize to resize the smaller dimension rather than the larger.
(fit around the given size rather inside the given size).

See also resize, Fill Area Flag ('^' flag)
http://www.imagemagick.org/Usage/resize/#fill


NOTE there is NO space between the numbers and the flag! and under windows you need to double up that flag!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize -> Crop -> Image Mask -> Merge Layers

Post by fmw42 »

NOTE there is NO space between the numbers and the flag! and under windows you need to double up that flag!
Anthony is quite correct. I missed the space before the ^. Sorry about that. Also I was not aware of your being on Windows. So if that is so, there are syntax differences as Anthony points out. For more details see
http://www.imagemagick.org/Usage/windows/
Post Reply