evanct Posted May 27, 2009 Share Posted May 27, 2009 What am I doing wrong here? This saves a plain rectangle without rounded corners to the specified directory. Turning on notices tells me nothing. <?php $tmpimg=imagecreatetruecolor(200,200); $color=imagecolorallocate($tmpimg,0,0,0); roundedRectangle($tmpimg,0,0,200,200,20,$color); imagejpeg($tmpimg,$path.$filename); function roundedRectangle($im,$x,$y,$end_x,$end_y,$radius,$color) { //create two rectangles to form a sort of "cross" shape imagefilledrectangle($im,$x,$y+$radius,$end_x,$end_y-$radius,$color); imagefilledrectangle($im,$x+$radius,$y,$end_x-$radius,$end_y,$color); $dia = $radius*2; //fill in the corners of the "cross" with ellipses to form a rounded rectangle imagefilledellipse($im, $x+$radius, $y+$radius, $radius*2, $dia, $color); imagefilledellipse($im, $x+$radius, $end_y-$radius, $radius*2, $dia, $color); imagefilledellipse($im, $end_x-$radius, $end_y-$radius, $radius*2, $dia, $color); imagefilledellipse($im, $end_x-$radius, $y+$radius, $radius*2, $dia, $color); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159952-rounded-rectangle-with-gd/ Share on other sites More sharing options...
grissom Posted May 27, 2009 Share Posted May 27, 2009 Man, I hate GD I always get brain ache. As a first step, try "commenting out" (ie by using the old // marks) the four lines which do the imagefilledellipse bit on the corners. Do you get a cross shape or still a rectangle ? Quote Link to comment https://forums.phpfreaks.com/topic/159952-rounded-rectangle-with-gd/#findComment-843644 Share on other sites More sharing options...
trevis Posted May 27, 2009 Share Posted May 27, 2009 When an image is created with imagecreatetruecolor() it has a black background by default. Try changing the color your rectangle is drawn in from black to white, and it should work. Quote Link to comment https://forums.phpfreaks.com/topic/159952-rounded-rectangle-with-gd/#findComment-843668 Share on other sites More sharing options...
MadTechie Posted May 28, 2009 Share Posted May 28, 2009 Your function isn't returning anything try this <?php $tmpimg=imagecreatetruecolor(200,200); $color=imagecolorallocate($tmpimg,0,0,0); $tmpimg = roundedRectangle($tmpimg,0,0,200,200,20,$color); imagejpeg($tmpimg,$path.$filename); function roundedRectangle($im,$x,$y,$end_x,$end_y,$radius,$color) { //create two rectangles to form a sort of "cross" shape imagefilledrectangle($im,$x,$y+$radius,$end_x,$end_y-$radius,$color); imagefilledrectangle($im,$x+$radius,$y,$end_x-$radius,$end_y,$color); $dia = $radius*2; //fill in the corners of the "cross" with ellipses to form a rounded rectangle imagefilledellipse($im, $x+$radius, $y+$radius, $radius*2, $dia, $color); imagefilledellipse($im, $x+$radius, $end_y-$radius, $radius*2, $dia, $color); imagefilledellipse($im, $end_x-$radius, $end_y-$radius, $radius*2, $dia, $color); imagefilledellipse($im, $end_x-$radius, $y+$radius, $radius*2, $dia, $color); return $im; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159952-rounded-rectangle-with-gd/#findComment-843691 Share on other sites More sharing options...
evanct Posted May 28, 2009 Author Share Posted May 28, 2009 When an image is created with imagecreatetruecolor() it has a black background by default. Try changing the color your rectangle is drawn in from black to white, and it should work. That worked. I see what's going on: I was simply mistaken about the nature of imagefilledrectangle and imagefilledellipse. I thought they would create a rounded rectangle SHAPE, but all they do is create a rounded rectangle within the rectangle created with imagecreatetruecolor. what i'm ultimately trying to do here is dynamically round the corners of photos i upload. Is there even a way to accomplish that with GD? If not that's fine, it's only a design preference, not strictly necessary. Essentially is there a way to create a transparent rectangle with imagecreatetruecolor? Quote Link to comment https://forums.phpfreaks.com/topic/159952-rounded-rectangle-with-gd/#findComment-843705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.