get("width"); $height = $obj1->get("height"); $image = imagecreatetruecolor($width, $height); imagealphablending($image,true); $white = ImageColorAllocate($image,255,255,255); ImageFilledRectangle($image,0,0,$width,$height,$white); for($i=0; $isetPNG(); $url[$i] = $obj->encodeGET($encode); $img = $this->loadpng($url[$i]); $opacity = $opacities[$i] *100; if($img != false){ if ($opacity != 100 && $opacity != "") { if(imagecolortransparent($img) > -1 ){ imagecopymerge($image, $img, 0, 0, 0, 0, $width, $height,$opacity); } else { $this->filter_opacity($img,$opacity); imagecopy($image, $img, 0, 0, 0, 0, $width, $height); } } else { imagecopy($image, $img, 0, 0, 0, 0, $width, $height); } @imagedestroy($img); } else{ $e = new mb_exception("weldMaps2PNG: unable to load image: " . $url[$i]); } } imagepng($image,$filename); imagedestroy($image); } /** * Old constructor to keep PHP downward compatibility */ function weldMaps2PNG($urls,$filename, $encode = true, $opacities=""){ self::__construct($urls,$filename, $encode, $opacities); } function loadpng ($imgurl) { $obj = new stripRequest($imgurl); $x = new connector($imgurl); // $f = $obj->get("format"); $im = @imagecreatefromstring($x->file); if(!$im){ $im = false; $e = new mb_exception("weldMaps2PNG: unable to load image: ".$imgurl); } return $im; } function filter_opacity( &$img, $opacity ) //params: image resource id, opacity in percentage (eg. 80) { if( !isset( $opacity ) ) { return false; } $opacity /= 100; //get image width and height $w = imagesx( $img ); $h = imagesy( $img ); //turn alpha blending off imagealphablending( $img, false ); //find the most opaque pixel in the image (the one with the smallest alpha value) $minalpha = 0; for( $x = 0; $x < $w; $x++ ) for( $y = 0; $y < $h; $y++ ) { $alpha = ( imagecolorat( $img, $x, $y ) >> 24 ) & 0xFF; if( $alpha < $minalpha ) { $minalpha = $alpha; } } //loop through image pixels and modify alpha for each for( $x = 0; $x < $w; $x++ ) { for( $y = 0; $y < $h; $y++ ) { //get current alpha value (represents the TANSPARENCY!) $colorxy = imagecolorat( $img, $x, $y ); $alpha = ( $colorxy >> 24 ) & 0xFF; //calculate new alpha if( $minalpha !== 127 ) { $alpha = 127 + 127 * $opacity * ( $alpha - 127 ) / ( 127 - $minalpha ); } else { $alpha += 127 * $opacity; } //get the color index with new alpha $alphacolorxy = imagecolorallocatealpha( $img, ( $colorxy >> 16 ) & 0xFF, ( $colorxy >> 8 ) & 0xFF, $colorxy & 0xFF, $alpha ); //set pixel with the new color + opacity if( !imagesetpixel( $img, $x, $y, $alphacolorxy ) ) { return false; } } } return true; } } ?>