1

We're using a CMS with WideImage built in and no scope to change this, however we've come up against a situation where we need to produce 300x300 images.

However the images that are uploaded at approx 100x100 in jpg and png format with various levels of transparency.

I'm trying to create a 300x300 canvas, and place the 100x100 image inside of it - however I want both the canvas to remain transparent, and the image placed on top to keep its transparency.

I've got

$image = WideImage::loadFromFile( $this->local_path );

$canvas = WideImage::createTrueColorImage(300, 300);
$canvas_bg = $canvas->allocateColor(255, 255, 255);
$canvas->fill(0, 0, $canvas_bg);

$resized_image = $canvas->merge($image);

However this obviously just adds a white background to the canvas, I cant figure out from their documentation how to make it transparent.

Thanks

owenmelbz
  • 6,180
  • 16
  • 63
  • 113

1 Answers1

0

How about:

$image = WideImage::loadFromFile($this->local_path);
$resized_image = $image->resizeCanvas(300, 300, 0, 0);

You can specify the X and Y location of the image within the new canvas as well as its width and height. $image->resizeCanvas(300, 300, "center", "center") works quite well.

Matt Raines
  • 4,149
  • 8
  • 31
  • 34
  • This does not solve the issue of lack of transparency on the new canvas, this produces something like -> http://i.imgur.com/kHp1CDq.jpg – owenmelbz May 26 '16 at 16:16
  • This is an example image of one thats not working, maybe will be useful to you http://s33.postimg.org/c6lfmia7j/wu9100.png – owenmelbz May 26 '16 at 16:21
  • Although Im now noticing, if i set the "scale" param to "down" it removes the black letterbox, but now the image is 250x250 even though im passing in 300 – owenmelbz May 26 '16 at 16:34
  • It works fine for me using `$image->resizeCanvas(300, 300, "center", "center")` and your image from postimg.org. My output is http://imgur.com/vkR6pyC. I'm using WideImage 11.02.19 on PHP 5.6.11 on Ubuntu, GD version 2.1.1. – Matt Raines May 26 '16 at 19:22