Skip to content

background color for jpeg from transparent png ? #194

Closed
patie opened this Issue Jan 31, 2013 · 3 comments

4 participants

@patie
patie commented Jan 31, 2013

when i upload transparent png - its uploaded jpeg with black background

can i set this background color? thanks

@avalanche123
Owner

Hi, yes you can with something like:

<?php

$image      = getUploadedImage();
$background = new Imagine\Image\Color('#fff');
$topLeft    = new Imagine\Image\Point(0, 0);
$canvas     = $imagine->create($image->getSize(), $background);

$canvas
    ->paste($image, $topLeft)
    ->save('/path/to/my/image.jpeg')
;
@romainneutron
Collaborator

Closing this one as it seems already solved

@rayrigam
rayrigam commented Jul 7, 2015

Shouldn't the default background be white when converting from transparent png to jpg? How can I tell if the uploaded png has a transparent background so that I only set the canvas as described above in those cases for converting to jpg?
There is a suggested way here: http://stackoverflow.com/a/8750947
Or should I just do the above pasting on a white canvas for all png images uploaded? Would that have a significant impact on memory used and performance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.