Page 1 of 1

How do I crop an image from a blank area

Posted: 2019-08-08T11:19:44-07:00
by disburden
Image

In A,The shaded portion of the picture represents an image,the blue dotted box indicates the area I want to crop.
I want a picture like B,the white space is transparent,But I can only get a picture of what C looks like,image pixels are always filled from the top.

The command I'm using looks something like this:
convert 32.jpg -crop 356x768+436+263 -background transparent -extent 356x768 output.png

Re: How do I crop an image from a blank area

Posted: 2019-08-08T12:01:45-07:00
by snibgo
I think you want the output to contain part of the input, plus some extra pixels that are transparent. You have a positive y-offset "+263" but your diagrams suggest you want a negative offset. I would use virtual pixels and a viewport, like this:

Code: Select all

magick in.png -set option:distort:viewport 400x400+100-100 -virtual-pixel None -distort SRT 1,0 +repage out.png

Re: How do I crop an image from a blank area

Posted: 2019-08-08T12:35:51-07:00
by disburden
Yeah, I'm using a negative y-offset,posted in a hurry,so a random copy of the previous test command.
I tried your command and it worked fine.Thank you very much!!

I would like to ask you another question.
I use the following command to round the corners of the picture.

Code: Select all

convert cut3.png -alpha set -virtual-pixel transparent -channel A -blur 0x32  -threshold 50% +channel cut4.png
If the picture is like C, i hope that only the upper left corner is rounded, but now all the four corners of the shaded part will be rounded.
How to don't ignore alpha channel when rounding corners?
Thanks again!
(In fact, I don't really understand those parameters,catch up with project schedule,you know...)

Re: How do I crop an image from a blank area

Posted: 2019-08-08T13:12:36-07:00
by GeeMack
disburden wrote: 2019-08-08T11:19:44-07:00In A,The shaded portion of the picture represents an image,the blue dotted box indicates the area I want to crop.
I want a picture like B,the white space is transparent,But I can only get a picture of what C looks like,image pixels are always filled from the top.
A great method was provided already by snibgo. You can also use "-extent" to get essentially the same result. You can cut out a portion of an input image and place it in a particular location on a certain size transparent canvas with a command like this...

Code: Select all

convert input.png -background none -extent 720x720+320-90 result.png
The geometry for the "-extent" operation first defines a width and height for the output. Then it sets the horizontal distance from the left edge to crop the input image like "+320", and the vertial distance from the top to crop the input image, like "-90". You can use negative numbers to specifiy the geometry of the crop.