Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,668 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,147 people online right now. Registration is fast and FREE... Join Now!




AlphaImageLoader not working with a php generated transparent image

 
Reply to this topicStart new topic

AlphaImageLoader not working with a php generated transparent image

jaelle
post 30 Jul, 2007 - 09:44 AM
Post #1


New D.I.C Head

*
Joined: 5 Apr, 2005
Posts: 24


My Contributions


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=20

Link to example image using AlphaImageLoader:
http://shopandexplore.com/dev/images/test.php

The 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;
}

?>

User is offlineProfile CardPM

Go to the top of the page

jaelle
post 31 Jul, 2007 - 01:40 PM
Post #2


New D.I.C Head

*
Joined: 5 Apr, 2005
Posts: 24


My Contributions


I just noticed that my AlphaImageLoader code snippet is referencing my local webserver still, and I do not see the option to edit a post... So, to clarify, it should read:

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://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')" />


However, that was not the problem and I am still stumped... *sigh*
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:55AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month