16

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.

Léo Léopold Hertz 준영
  • 6,788
  • 29
  • 91
  • 193
  • 1
    You could use imagemagick's `identify` to see how large the image is. – pfnuesel Apr 02 '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 02 '17 at 13:39
  • Your pseudocode is confusing, because reflexively I want to try it to see what's wrong with the result that it produces. If it's not contributing to the question, I recommend removing it. – Alex Mar 09 '20 at 13:34

2 Answers2

24

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
don_crissti
  • 79,330
  • 30
  • 216
  • 245
5

The command should be:

convert heart.png -gravity south -crop 100x70% +repage heart-out.png
GAD3R
  • 63,407
  • 31
  • 131
  • 192