Chopping images without gravity

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
t94j0
Posts: 2
Joined: 2016-05-31T13:15:45-07:00
Authentication code: 1151

Chopping images without gravity

Post by t94j0 »

Hello,
I have an array of (x,y) coordinate points in python and I would like to remove pixels that correspond to those coordinates. This is my first time using imageMagick, so I'm having some trouble. Right now, I'm using

Code: Select all

convert -chop 1x1+x+y input.png output.png
, but chop moves the image in a direction. Is there a way to chop and keep the part that was chopped transparent?

EDIT: I am using Version: ImageMagick 6.9.4-5 Q16 x86_64 on Mac.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Chopping images without gravity

Post by fmw42 »

draw a singe tranparent pixel at the coordinates you want

Code: Select all

convert yourimage.suffix -fill none -draw "matte X,Y point" result.png
where x,y is the point to make transparent.

If you have a list of points, you can make a string or file (unix syntax)

Code: Select all

string="matte x1,y1 point matte x2,y2 point ... matte xN,yN point"
convert yourimage.suffix -fill none -draw "$string" result.png
textfile.txt is as below

matte x1,y1 point
matte x2,y2 point
...
matte xN,yN point

Code: Select all

cat textfile.txt | convert yourimage.suffix -fill none -draw "-" result.png
t94j0
Posts: 2
Joined: 2016-05-31T13:15:45-07:00
Authentication code: 1151

Re: Chopping images without gravity

Post by t94j0 »

That works perfectly, thanks!
Post Reply