Rounded image using GD PHP

Hay guys i need rounded image with transparent background
this code give me this type image with background

i need this type of image

Take a look for this codes

    header ("Content-type: image/jpg"); 

    $images='2.jpg';
   $images2='1.jpg';

    $im = imagecreatefromjpeg("$images")or die("Cannot Initialize new GD image stream");
$im2 = imagecreatefromjpeg("$images2")or die("Cannot Initialize new GD image stream");
list($source_width, $source_height, $source_type) = getimagesize($images2);
list($w, $s, $source_type) = getimagesize($images);




 $corner_image = imagecreatetruecolor(
$source_width,
$source_height
);
$clear_colour = imagecolorallocate(
$corner_image,
255,
0,
255
);

imagefill($im2, 0, 0, $clear_colour);




imagecolortransparent(
$im2,
$clear_colour
);

 $mask = imagecreatetruecolor($source_width, $source_height);
    $black = imagecolorallocate($mask, 0, 0, 0);
    $magenta = imagecolorallocate($mask, 255, 0, 255);

imagefill($mask, 0, 0, $magenta);

imagefilledellipse(
$mask,
$source_width / 2,
$source_height / 2,
$source_width,
$source_height,
$black
);
  imagecolortransparent($mask, $black);


imagecopymerge(
$im2,
$mask,
0,
0,
0,
0,
$source_width,
$source_height,
100
);



 
$final_img = imagecreatetruecolor($w, $s);
imagealphablending($final_img, true);
imagesavealpha($final_img, true);




imagecopy($final_img, $im, 0, 0, 0, 1, $w, $s);
 imagecopy($final_img, $im2, 61, 97, 0, 0, $source_width, $source_height);



 imagejpeg($final_img);
  imagedestroy($final_img);

Can you talk us through our code…

i update cods you can now easily understand

I would still prefer to see some annotation, but you are not going to create an image with a transparent background using jpegs - you need png or gif for that.

Its also work in jpes I dont need back ground image transparent maybe first you can try this cods than you will easylly understand what I aks

Please clarify.

OK I will add images what I actchly need

Hmmm. To me “need” implies something one doesn’t have.
If you don’t have it it, I don’t see how you can post it.

Anyway, despite my comprehension difficulties, I’ll take a guess that you are looking for a way to create round jpg images.

If so, there is no such thing.
It’s a matter of cartesian vs. radian coordinates.

It is possible to display images that appear round, but source images are rectangular.

Ok can you give any example

The avatars here for one.

They are square images styled with CSS border-radius to make them display as round.

what how to css in gd

There isn’t any CSS in GD.

As I said there are no round source images.

IMHO the closest thing to want you want is what gandalf458 posted.
A png or gif with transparent background.

well i have a function to do this but when i call this function i cant add imagetest on image that why i need a deterrent way to do this

Sorry, but you’re all over the place here.
You mentioned nothing about text on images before.

Please take a step back. And then carefully and thoroughly list exactly what you are trying to accomplish.

text problem is not in this cods

OK, sorry.
Because there is no imagetest GD function I thought you typo’d imagettftext.

Anyway, please try to explain as best as you can exactly what you are trying to accomplish step-by-step.

i just want to transparent this pink background

Have you tried changing your jpegs to pngs and changing the appropriate functions?

You have to. As jpeg doesn’t support transparency. So you can do all the work you want, if you output a jpg, there will be color around that center circle. You will have to output a PNG.

There is a similar topic at

1 Like

not working same result as before