How to extract part of dvd cover image

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
popejobs

How to extract part of dvd cover image

Post by popejobs »

I've played with the various crop options but I'm lost. I'm trying to figure out the proper commandline to take a dvd boxcover image "Cover.jpg" and crop it so that i'm left with a new file "Folder.jpg" which has the left side image and spine in the center removed.

Given that the source cover images are of varying WxH dimensions yet nearly always the same aspect ratio, I assume I want to crop by percentage. in this example the Cover.jpg is 303px for the left part of the image plus 34px for the spine, leaving 303px for the right part of the image i want to keep. so 303/640 = 47.343 percent of the right side of the image that i want to keep.

Would someone mind helping me find the best operators to accomplish this? thanks in advance.

Image
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: How to extract part of dvd cover image

Post by GreenKoopa »

This sounds like a task easily accomplished using ImageMagick. Check out:
ImageMagick v6 Examples > Cutting and Bordering > Crop a Percentage of an Image
ImageMagick: Command-line Options > -gravity and -crop

If you still can't get it to work, let me know what you have tried and what didn't happen that you wanted.
popejobs

Re: How to extract part of dvd cover image

Post by popejobs »

i'm guessing the first step is getting the image to a fixed width, to not have to deal with percentages. so far i've got:

"convert.exe COVER.JPG -resize 800 -crop 420x0 FOLDER.JPG"

however that spits out two files: folder-0.jpg and folder-1.jpg. the contents of folder-1.jpg is exactly what I need, so how do I change the commandline so it doesn't write a folder-0.jpg?
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: How to extract part of dvd cover image

Post by GreenKoopa »

An initial resize to avoid percentages is certainly a valid way to go. Since your image geometry for the crop (420x0) specifies a size yet not an offset (location) you want, your are chopping your image into pieces (or tiles, of size 420x0, I guess). Specify an offset to get just one piece.

Here is my stab at a percentage solution:
convert Cover.jpg -gravity east -crop 47%x100% Folder.jpg

You seem to be using Windows, so remember to escape %s in batch files.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: How to extract part of dvd cover image

Post by GreenKoopa »

Or try replacing your -crop with -chop
popejobs

Re: How to extract part of dvd cover image

Post by popejobs »

GreenKoopa wrote:Or try replacing your -crop with -chop
that did it. much thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to extract part of dvd cover image

Post by fmw42 »

You don't have to work with percentages, -crop works with pixel coordinates

-crop follows this format

-crop WxH+X+Y +repage

W=width of section you want (after your resize if desired)
H=height of section you want
X=initial start x position (upper left corner of section you want)
Y=initial start y position (upper left corner of section you want)

+repage removes the virtual canvas which stores the crop coordinates

see http://www.imagemagick.org/Usage/crop/#crop_repage


If you leave off the +X+Y, IM tries to generate all non-overlapping subsections of size WxH

see http://www.imagemagick.org/Usage/crop/#crop_equal

Note you can also crop relative to a corner or side - see http://www.imagemagick.org/Usage/crop/#crop_gravity

So in this case, if you know you just want the right side of some WxH, use

convert image -gravity east -crop WxH+0+0 +repage result

or if you want percent (http://www.imagemagick.org/Usage/crop/#crop_percent), then if the W=47.343%

convert image -gravity east -crop 47.343x100%+0+0 +repage result

But pixels will ensure you get exactly what you want.
Post Reply