Any way to crop an image using multiple coordinates?

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
tirengarfio
Posts: 7
Joined: 2013-05-31T05:10:43-07:00
Authentication code: 6789

Any way to crop an image using multiple coordinates?

Post by tirengarfio »

Hi,

any way to crop an image using multiple coordinates?

For example:

Code: Select all

14, 45
30, 67,
35, 109
34, 1150
90, 1400
..
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any way to crop an image using multiple coordinates?

Post by snibgo »

I don't understand what you want. Images are always rectangular.
snibgo's IM pages: im.snibgo.com
tirengarfio
Posts: 7
Joined: 2013-05-31T05:10:43-07:00
Authentication code: 6789

Re: Any way to crop an image using multiple coordinates?

Post by tirengarfio »

Im working with this script:

http://iakob.com/canvas-area-draw/demo.html

https://github.com/fahrenheit-marketing ... -area-draw

as you can imagine, I would like to use those coordinates to crop the image in the server.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any way to crop an image using multiple coordinates?

Post by snibgo »

What do you mean "I would like to use those coordinates to crop the image"?

Your script could find the maximum and minimum x-coordinates, and maximum and minimum y-coordinates, and crop to those.

Or it might turn everything inside the polygon black. Or everything outside white. Or everything outside transparent.
snibgo's IM pages: im.snibgo.com
tirengarfio
Posts: 7
Joined: 2013-05-31T05:10:43-07:00
Authentication code: 6789

Re: Any way to crop an image using multiple coordinates?

Post by tirengarfio »

snibgo wrote:What do you mean "I would like to use those coordinates to crop the image"?
As you can see on the demo, with that script you can draw an area which coordinates are inserted in an input field. After submitting the form, I would use those coordinates to crop the image, since I'm interested in showing only that area in my website frontend.
snibgo wrote:Your script could find the maximum and minimum x-coordinates, and maximum and minimum y-coordinates, and crop to those.
but in that case the area will be a square, showing parts of the image that I'm not interested in. I just want the area I selected freely.
snibgo wrote:Or everything outside white.
In this case, could I drop using Imagemagick the area different from the white color? has Imageimagick any function to do this?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any way to crop an image using multiple coordinates?

Post by snibgo »

I still don't understand what you want, but this might be it. Windows BAT syntax. Adjust for other languages.

Code: Select all

convert ^
  in.png ^
  ( +clone -fill Black -colorize 100 ^
    -fill White ^
    -draw "polygon 208,221 208,202 198,199 201,191 218,176 229,155" ^
  ) ^
  -alpha off ^
  -compose CopyOpacity -composite ^
  -trim +repage ^
  out.png
snibgo's IM pages: im.snibgo.com
Post Reply