15

I want to cut 30% from the top of the image. I know the thread How to cut a really large raster image into smaller chunks? but there is no successful approach because I cannot find a distance measure of convert from zero to the end, only by absolute value dimensions. Pseudocode

convert -crop-y -units-percentage 0x30 heart.png 

Fig. 1 Input figure

enter image description here

I can do the task with LaTeX's adjustbox but the output in the pdf file is not really end result but a presentation of it. So copying the image from the pdf document yields the original image. So this approach failed.

  • 1
    You could use imagemagick's identify to see how large the image is. – pfnuesel Apr 2 '17 at 11:20
  • The general approach is to insert the value needed on the command line using $(command). You then just need to write a command line that can calculate the value needed. Here you would ask convert to describe the image and pipe it to awk where you can match the value you need and do the necessary calculation and print out the result. – Thorbjørn Ravn Andersen Apr 2 '17 at 13:39
23

You can crop a percentage of your image though in this case, to avoid running additional commands to get the image height and width (in order to calculate crop offset which by default is relative to top-left corner) you'll also have to crop relative to gravity (so that your crop offset position is relative to the bottom-left corner of the image):

convert -gravity SouthWest -crop 100x70%x+0+0 infile.jpg outfile.jpg
  • Confirmed, this approach works! - - You can reverse this approach etc by NorthWest to cut from bottom. Great! – Léo Léopold Hertz 준영 Apr 2 '17 at 11:35
5

The command should be:

convert heart.png -gravity south -crop 100x70% +repage heart-out.png
  • 1
    @LéoLéopoldHertz준영 I misunderstand the question , try my edit please – GAD3R Apr 2 '17 at 11:45
  • 1
    Your new approach cuts by absolute units, not by percentages. Now, the correct cut direction from the top. – Léo Léopold Hertz 준영 Apr 2 '17 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.