Image: Transparency on PNG

Created on 7 May 2016  路  6Comments  路  Source: Intervention/image

Hi

I save from original png with transparency and when i save loose the transparency and put a black background.

$imageObj = Image::make($request->file('activityUploadPhoto'))->orientate();
$imageName = substr(md5(Auth::user()->id), -10) . '_' . md5(microtime()) . '.' . $request->file('activityUploadPhoto')->getClientOriginalExtension();
$imageObj->save(config('paths.storage_tmp_imgs') . $imageName)

I have this version "version": "2.3.7",

Is a bug?

Thanks

Most helpful comment

Like this:

$png = Image::make('transparent.png');
$jpg = Image::canvas($png->width(), $png->height(), '#ff0000');
$jpg->insert($png);
$jpg->save('foo.jpg');

All 6 comments

I'm having a similar issue, where the PNG's shadow that is semi transparent is converted to flat black.

If you upload this....

screen shot 2016-05-25 at 7 19 10 pm

to this...
https://www.apps.regenr8web.com.au/image-preparation/

you get this...
prepared-image-5745700c12bbe

The controller simply resizes to max size and saves as JPEG with quality of 85.

Thoughts or ideas? Most recent version of the plugin (as of right now).

JPEG does not support alpha channel / transparency. If you want the background in another color than black, I would suggest you create an empty image with canvas() with the desired background color and insert() your semi-transparent image into this container.

Like this:

$png = Image::make('transparent.png');
$jpg = Image::canvas($png->width(), $png->height(), '#ff0000');
$jpg->insert($png);
$jpg->save('foo.jpg');

with imagick run correctly the plugin, with gd no

that did the trick with both GD and imagick drivers.

@olivervogel I wonder if this is a sensible default that should be apart of the framework. Is this a pull request you would consider if I put it together (or someone else)?

I figure if the image is being converted to a jpg, by default it should have a white background and keep the original images transparency (with the white behind it of course).

I think full transparency (seen in the corners of the image above) is converted to white and everything in between (like the shadow in the image above) becomes black. That's just the way GD works.

If you want it any another way, try my example above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

divdax picture divdax  路  7Comments

dragonfire1119 picture dragonfire1119  路  4Comments

knif3rdev picture knif3rdev  路  6Comments

lasithg picture lasithg  路  3Comments

REPTILEHAUS picture REPTILEHAUS  路  5Comments