Page 1 of 1

-trim and -extend does not modify clipping path correctly

Posted: 2018-10-04T10:33:57-07:00
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

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

Posted: 2018-10-17T15:05:08-07:00
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.

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

Posted: 2018-10-18T06:29:26-07:00
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

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

Posted: 2018-10-18T09:46:56-07:00
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.

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

Posted: 2019-10-28T05:30:23-07:00
by phoenix408
Clipping Path prior to Trim

Code: Select all

M 394.428 2374.08
C 394.428 2374.08 363.458 2378.17 363.652 2357.86
C 363.845 2337.54 291.802 238.659 291.802 238.659
L 307.982 221.676
L 291.802 206.2
L 291.802 14.3015
C 291.802 14.3015 290.868 0.360203 304.407 0.360203
C 317.946 0.360203 2090.42 0.360203 2090.42 0.360203
C 2090.42 0.360203 2108.66 -0.268936 2108.66 16.0892
C 2108.66 32.4477 2108.66 206.761 2108.66 206.761
L 2096.49 222.757
L 2108.66 235.79
C 2108.66 235.79 2110.85 439.623 2102.48 720.919
C 2083.85 1347.09 2045.54 2357.09 2045.54 2357.09
C 2045.54 2357.09 2048.49 2375.4 2025.88 2376.62
C 2003.26 2377.83 1384.02 2399.66 1182.12 2399.66
M 1216.76 66.2616
C 1240.2 66.2616 1259.21 85.871 1259.21 110.06
C 1259.21 134.25 1240.2 153.859 1216.76 153.859
C 1193.31 153.859 1174.3 134.25 1174.3 110.06
Clipping Path Post image.Trim();

Code: Select all

M 299.765 2374.08
C 299.765 2374.08 276.228 2378.17 276.375 2357.86
C 276.522 2337.54 221.769 238.659 221.769 238.659
L 234.067 221.676
L 221.769 206.2
L 221.769 14.3015
C 221.769 14.3015 221.059 0.360203 231.349 0.360203
C 241.639 0.360203 1588.72 0.360203 1588.72 0.360203
C 1588.72 0.360203 1602.58 -0.268936 1602.58 16.0892
C 1602.58 32.4477 1602.58 206.761 1602.58 206.761
L 1593.33 222.757
L 1602.58 235.79
C 1602.58 235.79 1604.25 439.623 1597.89 720.919
C 1583.73 1347.09 1554.61 2357.09 1554.61 2357.09
C 1554.61 2357.09 1556.85 2375.4 1539.67 2376.62
C 1522.48 2377.83 1051.85 2399.66 898.414 2399.66
M 924.734 66.2616
C 942.555 66.2616 957.001 85.871 957.001 110.06
C 957.001 134.25 942.555 153.859 924.734 153.859
C 906.914 153.859 892.468 134.25 892.468 110.06
The path has clearly been inset by number of pixels trimmed from corners. ImageMagic is modifying path on crop as if it was doing a resize. I would like to donate to ImageMagic development team to fix this issue if possible.