-trim and -extend does not modify clipping path correctly

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
grburgos
Posts: 9
Joined: 2018-10-03T05:38:33-07:00
Authentication code: 1152

-trim and -extend does not modify clipping path correctly

Post by grburgos »

There seems to be a bug that "-trim" and "-extent" they don't seem to modify the clip path correctly.

Example
For some reason the clipping path is changed and shows smaller than it should be.

I use Gimp 2.8 to open the file and look at the clipping path called "Path 1". You can notice that after I run the command

Code: Select all

convert origin.tiff -trim +repage -resize 500x500 -background white -gravity north -extent 500x500 result.tiff
the clipping path is smaller than the image of the product.
https://www.dropbox.com/s/lwlq4dwbihzxd ... h.png?dl=0

If I use the plain -resize command, the clipping path does align with the image.
https://www.dropbox.com/s/xddloukntpmxm ... h.png?dl=0

Code: Select all

convert origin.tiff  -resize 500x500 result.tiff

More details
http://www.imagemagick.org/discourse-se ... =1&t=34803
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: -trim and -extend does not modify clipping path correctly

Post by dlemstra »

This is not a bug but the expected result. The clipping path is never resized. Sometime you are lucky and you get the correct clip path because of how it stored in the image profile. I don't think we will be able to add support for this anytime soon.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
grburgos
Posts: 9
Joined: 2018-10-03T05:38:33-07:00
Authentication code: 1152

Re: -trim and -extend does not modify clipping path correctly

Post by grburgos »

If that would be the case then why does the -resize alone does adjust the clipping path but when I use the -extent the clipping path becomes incorrect.

If I use this:

Code: Select all

convert origin.tiff -trim +repage -resize 4800x4800 -background white -gravity center -extent 4800x4800 -compress lzw tiff.tiff
The source image is 800x600 and I'm requesting an image several times larger. If what you state that the clipping path is never modified. The clipping path would stay at a size less than 800x600. However, after I run the command above the clipping path is 3684x3707 in size.

Also, I tried removing the trim and I got the same image condition. I have already tried a plain -resize and the clipping path was kept. Which means that the -extent command is the one resizing the clipping path incorrectly.

Using IM 7.0.8-12
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: -trim and -extend does not modify clipping path correctly

Post by dlemstra »

The clip path is stored in a vector format and the positions are relative to the 0x0 position of the image. And that does not change when you resize the image. The relative position is still the same. But this changes when you extent the image. The start position of the clipping path is no longer at the same position. We don't modify the path when we resize the image. This show that the path still has the same size but now no longer starts at the correct position because you trimmed the image:

Code: Select all

convert origin.tiff -trim +repage -clip ( -size 615x532 xc:rgba(255,0,0,0.5) ) -compose over -composite test.png
We never touch the clipping path.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply