Slicing off the bottom 20% of an 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
Legal

Slicing off the bottom 20% of an image

Post by Legal »

I have a stack of multi-page PDFs that I'm feeding through IM to convert to JPGs, but I've been struggling. I have two questions:

1) I can convert every page of the PDF to individual .jpg files with the command

Code: Select all

convert -density 190 filename.pdf filename.jpg
. How can I convert just the first page of the PDF (or just a single page inside the PDF?) Is this possible?
2) Even if I can't pluck out a single page, I'd like to cut off the bottom 20% of every page and save them as separate .jpg files. How can I do this?

I really appreciate any help you can provide. Thank you!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Slicing off the bottom 20% of an image

Post by Bonzo »

Work on page 1: filename.pdf[0] page 2 filename.pdf[1] etc.

If you are working on standard size pages try this:
work out the 20% height size, page width, 80% page height ( all in pixels ) and:

Code: Select all

convert filename.pdf -crop pagewidth,20%height+pagewidth+80%height +repage output.jpg
Legal

Re: Slicing off the bottom 20% of an image

Post by Legal »

Bonzo,

The page selection bit works perfectly, thank you! I'm still confused about the repaging part, though. The image is 1615(w) x 2090(h). Where do those numbers fit in your example? I'm looking to keep just the bottom 20%.

I really appreciate your help.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Slicing off the bottom 20% of an image

Post by magick »

As an example, try this:
  • convert rose: -gravity south -crop 100x20% +repage bottom.png
Legal

Re: Slicing off the bottom 20% of an image

Post by Legal »

This worked swimmingly--thank you both so much.
Legal

Re: Slicing off the bottom 20% of an image

Post by Legal »

Hm. Slightly different issue: it looks like I'm losing a lot of quality compared to the original PDF. I tried futzing with -density, but that didn't seem to help.

I've been using this:

Code: Select all

convert Filename.pdf -gravity south -crop 100x20% +repage Filename.jpg
...to convert every page of a PDF to a separate .jpg. Unfortunately, the final file looks like it shrinks by about 10% (width) and loses a bundle in quality (particularly, it changes to straight up B&W rather than grayscale).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Slicing off the bottom 20% of an image

Post by fmw42 »

try using supersampling (will take longer but usually gets better quality)

convert -density 288 Filename.pdf -resize 25% -gravity south -crop 100x20% +repage Filename.jpg

density 288 is 4x72, where 72 is nonminal, so you reduce afterwards by 1/4=25%
Legal

Re: Slicing off the bottom 20% of an image

Post by Legal »

Hm... that seems to have just shrunk it to 25% of its size.
Legal

Re: Slicing off the bottom 20% of an image

Post by Legal »

Alright, I have no idea what I changed, but I futzed with it until it worked. I now have:

Code: Select all

convert.exe -density 190 Filename.pdf -gravity south -crop 100x20% +repage Filename.jpg
Now to just add one more issue, I'm trying to slice off ten percent from the left and right. I tried "-crop right" and "-crop east" but those don't seem to work. What am I looking for, and where do I place it in the string for the intended result?

I really appreciate any help you can provide.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Slicing off the bottom 20% of an image

Post by fmw42 »

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

add -shave 10x0% right after the input or right after -crop

Good reading and lots of examples is at http://www.imagemagick.org/Usage/
Legal

Re: Animated Gifs

Post by Legal »

You folks are tremendously helpful, thank you. The shaving worked swimmingly!

I have a slightly different question. I've got the commands I want to run now, which looks like this:

Code: Select all

convert.exe" -density 150 Filename.pdf -gravity south -crop 100x20% -shave 20x0% +repage Filename.gif
Unfortunately, unlike when I was using .jpg as the output file, the .gif takes a multi-page .pdf and converts it to an animated .gif. This isn't the result I want--I'd like separate .gifs for each file (as it did when it was a .jpg). I've reviewed the Usage guide regarding .gifs, but I was unable to locate a solution. Is this where I'm supposed to use the -dispose parameter? If so, where should it be placed.

I appreciate your patience with my questions,

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

Re: Slicing off the bottom 20% of an image

Post by fmw42 »

see +adjoin at http://www.imagemagick.org/script/comma ... php#adjoin

or just name your output image, Filename_%d.gif
Legal

Re: Slicing off the bottom 20% of an image

Post by Legal »

Thank you so much for your help, that works!
Post Reply