image icon indicating copy to clipboard operation
image copied to clipboard

Trim problem

Open ghost opened this issue 7 years ago • 6 comments

Hi

I am trying to use the trim() (with imagick driver), in order to remove the unnecessary transparent space in the image below :

Transparent PNG to be trimmed

Here's the code that comes with it :

use Intervention\Image\ImageManagerStatic as Image;

Image::configure(['driver' => 'imagick']);

$image = Image::make('public/trim.png')->trim()
            ->save('public/trimmed.png');

The result of that code, is that I am getting a 1x1 transparent image.

I tried another approch with the trim method, like ->trim('transparent') or ->trim('transparent', null, 10) . Solution that I found here : Issue #156

I tried to use other features, like greyscale(), and that works perfectly.

Other informations :

PHP version : 7.1.5 PHP imagick : 3.4.3_2 Imagemagick : 7.0.5-10

ghost avatar Jun 08 '17 10:06 ghost

I have this problem too. It seems, like the borderImage() method makes the whole image transparent.

$image = new Imagick('/some/image/with/a/transparent/background.png');
$pixel = $image->getImagePixelColor(0, 0);
$image->borderImage($pixel, 1, 1); // now the image is fully transparent :(
//$image->trimImage(0); // -> results in 1x1 image
//$image->setImagePage(0, 0, 0, 0); 
$image->writeImage("/tmp/test.png");

i think it happens since imagemagick 7, but im not sure

PHP version : 7.2.1 PHP imagick : 3.4.3 Imagemagick : 7.0.7-21

schelmo avatar Jan 12 '18 11:01 schelmo

Same issue as @schelmo.

PHP version: 7.0.27 PHP imagick: 3.4.3 Imagemagick: 7.0.7-22

jantzenw avatar Jan 30 '18 20:01 jantzenw

Downgrading to Imagemagick 6 fixed this issue for me

ntzm avatar Aug 16 '18 08:08 ntzm

Still an issue, any solution to this?

satoved avatar Oct 14 '19 18:10 satoved

@satoved or @ntzm, have you found a solution that uses Imagemagick 7?

lhilton avatar Nov 03 '20 19:11 lhilton

Think I'm experiencing this issue as well.

PHP version: 7.4.16 PHP imagick: 3.4.4 Imagemagick: 7.0.11-3 Q16 x86_64

elazar avatar Mar 18 '21 17:03 elazar

The implementation of this function was rather poor and very resource-hungry. I decided to drop this function in the new version 3 of Intervention Image.

olivervogel avatar Dec 08 '23 18:12 olivervogel