Jump to content

GD Library issue with radius corner


sassenach

Recommended Posts

Hi,

 

I am using GD Library to reshape my images, as well as add to them.

 

You can see them here:

http://noneonrecord.com/display_pages.php?page=7

 

I use this below to create the png radius shape:

imagecreatefrompng('http://noneonrecord.com/backend/images/rounded_corner_40px.png');

 

After adding:

PHP Code:

 $white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0); 

 

 

For example to the left corner:

PHP Code:

if ($topleft == true) {
    $dest_x = 0;  
    $dest_y = 0;  
    imagecolortransparent($corner_resized, $black); 
    imagecopymerge($image, $corner_resized, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
} 

 

 

It turns the PNG file to Black, then i see the corner with a bit black on the site.

 

if i change the color, even to nuteral, this is what i get:

http://www.noneonrecord.com/Untitled-1.jpg

 

Why did it not stay white as the orginal PNG file?

 

i retrieve my image this way:

function displayFontonImage($src, $radius = 10, $folder, $text = '', $r = 0, $g = 0, $b = 0, $x = 6, $y = 20, $ceffect = 0){
    return '<img src="includes/roundcorners.php?src='.$src.'&radius='.$radius.'&folder='.$folder.'&text='.$text.'&r='.$r.'&g='.$g.'&b='.$b.'&posx='.$x.'&posy='.$y.'&ceffect='.$ceffect.'" border="0" alt="" />';
}

 

here is the "roundcorners.php" page code:

<?php
/*
Just paste the code above and save it in a php file. Make the necessary changes to the $images_dir and $corner_source variables.
Link the src attribute of your image to that file, using the following GET variables:

"src": name of the image file 
"folder": folder name withing site_uploads folder
"text": to display over the image
"r g b": to display colors of font
"pos x y: to display font according to x y
"radius" (optionnal): value that represents (in pixels) the radius of the corners (used to resize the corner image) 
"angle" (optionnal): value that represents (in degrees) the rotation angle 
"topleft=no" (optionnal): doesn't round the top-left corner 
"bottomleft=no" (optionnal): doesn't round the bottom-left corner 
"bottomright=no" (optionnal): doesn't round the bottom-right corner 
"topright=no" (optionnal): doesn't round the top-right corner 
*/
$image_file = $_GET['src'];
$image_folder = $_GET['folder'];
$r = (int) $_GET['r'];
$g = (int) $_GET['g'];
$b = (int) $_GET['b'];
$ceffect = (int) $_GET['ceffect'];
$posx = (isset($_GET['posx']) and $_GET['posx'] != 0) ? $_GET['posx'] : 6;
$posy = (isset($_GET['posy']) and $_GET['posy'] != 0) ? $_GET['posy'] : 20;
$text = $_GET['text'];
$corner_radius = isset($_GET['radius']) ? $_GET['radius'] : 20; // The default corner radius is set to 20px
$angle = isset($_GET['angle']) ? $_GET['angle'] : 0; // The default angle is set to 0º
$topleft = (isset($_GET['topleft']) and $_GET['topleft'] == "no") ? false : true; // Top-left rounded corner is shown by default
$bottomleft = (isset($_GET['bottomleft']) and $_GET['bottomleft'] == "no") ? false : true; // Bottom-left rounded corner is shown by default
$bottomright = (isset($_GET['bottomright']) and $_GET['bottomright'] == "no") ? false : true; // Bottom-right rounded corner is shown by default
$topright = (isset($_GET['topright']) and $_GET['topright'] == "no") ? false : true; // Top-right rounded corner is shown by default

$images_dir = 'http://www.noneonrecord.com/site_uploads/';
$corner_source = imagecreatefrompng('../images/rounded_corner_40px.png');

$corner_width = imagesx($corner_source);  
$corner_height = imagesy($corner_source);  
$corner_resized = ImageCreateTrueColor($corner_radius, $corner_radius);
ImageCopyResampled($corner_resized, $corner_source, 0, 0, 0, 0, $corner_radius, $corner_radius, $corner_width, $corner_height);

$corner_width = imagesx($corner_resized);  
$corner_height = imagesy($corner_resized);  
$image = imagecreatetruecolor($corner_width, $corner_height);  
preg_match("'^(.*)\.(gif|jpe?g|png)$'i", $image_file, $ext);
switch (strtolower($ext[2])) {
    case 'jpg' : 
    case 'jpeg': $image = imagecreatefromjpeg($images_dir . $image_folder .'/'. $image_file);
                 break;
    case 'gif' : $image = imagecreatefromgif($images_dir . $image_folder .'/'. $image_file);
                 break;
    case 'png' : $image = imagecreatefrompng($images_dir . $image_folder .'/'. $image_file);
                 break;
    default    : $stop = true;
                 break;
}
$size = getimagesize($images_dir . $image_folder .'/'. $image_file); // replace filename with $_GET['src'] 
$white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0);

// Top-left corner
if ($topleft == true) {
    $dest_x = 0;  
    $dest_y = 0;  
    imagecolortransparent($corner_resized, $black); 
    imagecopymerge($image, $corner_resized, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
} 

// Bottom-left corner
if ($bottomleft == true) {
    $dest_x = 0;  
    $dest_y = $size[1] - $corner_height; 
    $rotated = imagerotate($corner_resized, 90, 0);
    imagecolortransparent($rotated, $black); 
    imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);  
}

// Bottom-right corner
if ($bottomright == true) {
    $dest_x = $size[0] - $corner_width;  
    $dest_y = $size[1] - $corner_height;  
    $rotated = imagerotate($corner_resized, 180, 0);
    imagecolortransparent($rotated, $black); 
    imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);  
}

// Top-right corner
if ($topright == true) {
    $dest_x = $size[0] - $corner_width;  
    $dest_y = 0;  
    $rotated = imagerotate($corner_resized, 270, 0);
    imagecolortransparent($rotated, $black); 
    imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);  
}


if(isset($text)){    //adds text above image    
    $text = wordwrap($text, 35, "\n");//wraps text every 15 characters
    if (ini_get('magic_quotes_gpc')) {$text = stripslashes($text);}// Address Magic Quotes.
    $fonttype = $_SERVER['DOCUMENT_ROOT']."/site_uploads/COPRGTB.TTF"; //verdana bold font        
    if($ceffect == 2) {    //outer glow
        $addcolor  = imagecolorallocate($image, 255, 255, 190);    //applies outer glow colors
        imagettftext ($image, 12, 0, $posx+1, $posy+1, $addcolor, $fonttype, $text);//displays shadow the font
    } elseif($ceffect == 1) {    //shadow
        $addcolor  = imagecolorallocate($image, 70, 70, 70); //applies drow shadow colors
        imagettftext ($image, 12, 0, $posx+1, $posy+1, $addcolor, $fonttype, $text);//displays shadow the font
    }    
    $color = ImageColorAllocate($image,$r,$g,$b);//adds font color to the image      
    imagettftext ($image, 12, 0, $posx, $posy, $color, $fonttype, $text);//displays the font
}

// Rotate image
$image = imagerotate($image, $angle, $white);

// Output final image
imagejpeg($image);

imagedestroy($image);  
imagedestroy($corner_source);

?> 

 

 

I hope this made sense.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/99488-gd-library-issue-with-radius-corner/
Share on other sites

hiya,

 

this screen shot: http://www.noneonrecord.com/Untitled-1.jpg shows black radius corners.

on the live site http://noneonrecord.com/display_pages.php?page=7 look at the 3rd image at the bottom right. you see the black corners sticking out a bit?

 

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.