I am trying to create a php script that will add transparent curved corners to any image. So far, I have it working beautifully in IE7,FF,Safari,etc. However, I am trying to use the AlphaImageLoader function to properly display the transparency in IE6. This is where I am having some difficulty and unfortunately, ignoring IE6 is not an option. Instead of having transparent corners, I have bright green corners that I was using for my transparency. I'm wondering if PHP is generating this in a weird way that the AlphaImageLoader does not recognize? Or perhaps I am using the AlphaImageLoader wrong? If anyone has some insight here, it would be much appreciated.
Link to example image:http://shopandexplore.com/dev/images/image...urved_radius=20Link to example image using AlphaImageLoader:http://shopandexplore.com/dev/images/test.phpThe code I'm using for the AlphaImageLoader filter:CODE
<img src="image.php?img=http://shopandexplore.com/dev/images/categories/real-estate-228x228.jpg&width=228&height=228&curved_radius=20" style="width:228px;height:228px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://localhost/clients/shopandexplore.com/dev/images/image.php?img=http://shopandexplore.com/dev/images/categories/real-estate-228x228.jpg&width=228&height=228&curved_radius=20',sizingMethod='scale')" />
My php script for adding the curved corners:CODE
<?php
Header("Content-Type: image/png");
$extension = getExtension($_REQUEST['img']);
switch($extension) {
case ".jpg":
$im = imagecreatefromjpeg($_REQUEST['img']);
break;
case ".gif":
$im = imagecreatefromgif($_REQUEST['img']);
break;
case ".png":
$im = imagecreatefrompng($_REQUEST['img']);
break;
}
$currentWidth = imagesx($im);
$currentHeight = imagesy($im);
//get curved corners
$frame = createFrame();
//create the thumbnail image holder that will be displayed
$thumbnail = imagecreatetruecolor($_REQUEST['width'],$_REQUEST['height']);
//copy image onto thumbnail
imagecopyresized($thumbnail,$im,0,0,0,0,$_REQUEST['width'],$_REQUEST['height'],$currentWidth,$currentHeight);
//copy frame onto thumbnail
imagecopymerge($thumbnail,$frame,0,0,0,0,$_REQUEST['width'],$_REQUEST['height'],100);
//make curves transparent
$curveTransparency = imagecolorallocate($thumbnail,61,255,0);
if (!$_REQUEST['view_masks']) {
imagecolortransparent($thumbnail,$curveTransparency);
}
//output image
imagepng($thumbnail);
//free up resources
imagedestroy($frame);
imagedestroy($thumbnail);
imagedestroy($im);
function getExtension($imageName) {
$extensionStart = strrpos($imageName,".");
$extensionLength = strlen($imageName) - $extensionStart + 1;
return strtolower(substr($imageName,$extensionStart,$extensionLength));
}
function createFrame() {
$frame = imagecreatetruecolor($_REQUEST['width'],$_REQUEST['height']);
if ($_REQUEST['curved_radius'] > 0) {
//color to use for curves. (green)
$curveTransparency = imagecolorallocate($frame,61,255,0);
//color to use for transparency (magenta)
$transparencyColor = imagecolorallocate($frame,255,0,250);
//create rectangle the color you want the frame to be
imagefilledrectangle($frame,0,0,$_REQUEST['width'],$_REQUEST['height'],$curveTransparency);
//create shape to cut away from rectangle
//top left corner
imagefilledarc($frame,$_REQUEST['curved_radius'],$_REQUEST['curved_radius'],$_REQUEST['curved_radius'] * 2,$_REQUEST['curved_radius'] * 2,180,270,$transparencyColor,IMG_ARC_PIE);
//top right corner
imagefilledarc($frame,$_REQUEST['width'] - $_REQUEST['curved_radius'],$_REQUEST['curved_radius'],$_REQUEST['curved_radius'] * 2,$_REQUEST['curved_radius'] * 2,270,0,$transparencyColor,IMG_ARC_PIE);
//bottom right corner
imagefilledarc($frame,$_REQUEST['width'] - $_REQUEST['curved_radius'],$_REQUEST['height'] - $_REQUEST['curved_radius'] + 1,$_REQUEST['curved_radius'] * 2,$_REQUEST['curved_radius'] * 2,0,90,$transparencyColor,IMG_ARC_PIE);
//bottom left corner
imagefilledarc($frame,$_REQUEST['curved_radius'],$_REQUEST['height'] - $_REQUEST['curved_radius'],$_REQUEST['curved_radius'] * 2,$_REQUEST['curved_radius'] * 2,90,180,$transparencyColor,IMG_ARC_PIE);
//rectangles to fill in everything else
imagefilledrectangle($frame,$_REQUEST['curved_radius'],0,$_REQUEST['width'] - $_REQUEST['curved_radius'],$_REQUEST['height'],$transparencyColor);
imagefilledrectangle($frame,0,$_REQUEST['curved_radius'],$_REQUEST['width'],$_REQUEST['height'] - $_REQUEST['curved_radius'],$transparencyColor);
//ugly fix corner not lining up right (it was showing up 1px above the bottom of the image for some unknown reason...
imagerectangle($frame,0,0,$_REQUEST['width'],$_REQUEST['height']-1,$curveTransparency);
//cut out shape from rectangle
if (!$_REQUEST['view_masks']) {
imagecolortransparent($frame,$transparencyColor);
}
}
return $frame;
}
?>