简体   繁体   中英

WideImage - Canvas with transparent background

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM