PHP GD: merge a blurry rectangle -


i need merge blurry rectangle on image (a white rectangle). tried imagesavealpha() unfortunately background of rectangle remains black, , want gradient red white.

here code:

<?php $width = 200; $height = 180;  $bw = $bh = 30;  $img1 = imagecreatetruecolor($width, $height); $img2 = imagecreatetruecolor($width, $height);  $white = imagecolorallocate($img1, 255, 255, 255); $red = imagecolorallocate($img2, 255, 0, 0); imagefilledrectangle($img1, 0, 0, 100, 100, $white); imagefilledrectangle($img2, 5, 5, 25, 25, $red);  imagefilter($img2, img_filter_gaussian_blur); imagefilter($img2, img_filter_gaussian_blur); imagefilter($img2, img_filter_gaussian_blur); imagefilter($img2, img_filter_gaussian_blur); imagefilter($img2, img_filter_gaussian_blur);  imagesavealpha($img2, true);  imagecopymerge($img1, $img2, 20, 20, 0, 0, $bw, $bh, 100);  header('content-type: image/png'); imagepng($img1);  imagedestroy($img1); 

the restulting image is:

enter image description here

if want blurred red rectangle on white background code can simplified this:

<?php $width = 200; $height = 180;  $img = imagecreatetruecolor($width, $height);  // fill opaque white. imagefill($img, 0, 0, 0x00ffffff);  // draw rectangle in opaque red. imagefilledrectangle($img, 5, 5, 25, 25, 0x00ff00000);  ($i = 0; $i < 5; $i++) {     imagefilter($img, img_filter_gaussian_blur); }  header('content-type: image/png'); imagepng($img); imagedestroy($img); 

result (of course white background blends page background...):

result

if want able blend red rectangle background colour (full alpha blending) might out of luck. far can tell img_filter_gaussian_blur doesn't support alpha values (i'm using php 7.0.3).


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -