Varun Sridharan
Varun Sridharan

Reputation: 1978

Generate Images using php

How i can generate the below image using php

Image Original Source

I used the below php code to generate the image

<?php
header("Content-Type: image/png");
$im = imagecreate(300, 300);
$background_color = imagecolorallocate($im, 21, 125, 126);
$black = ImageColorAllocate($im, 0, 0, 0);

$blue = ImageColorAllocate($im, 0, 0, 255);
$white = ImageColorAllocate($im, 255, 255, 255);

ImageFilledEllipse($im, 50, 120, 75, 75, $white);
ImageFilledEllipse($im, 250, 100, 75, 75, $white);



imagepng($im);
imagedestroy($im);
?>

But i dint get the original image smoothness

PHP Generated Image

enter image description here

Upvotes: 1

Views: 163

Answers (3)

Jon Taylor
Jon Taylor

Reputation: 7905

If you are creating an image of a particular size then no matter how you do it, when you zoom into such an image you are always going to get unsmooth edges.

The problem is you are zooming in on the browser after the PHP image has been rendered. Why not use a vector based library in javascript to draw your images, that way when you zoom in the vector graphic is redrawn for the appropriate scale. Eliminating your jagged edges.

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324600

imagecreate creates a palette-based image, which does not include anti-aliasing (in particular because you haven't allocated the "in-between" colours). Try imagecreatetruecolor instead.

Upvotes: 1

Apply filter to your image using imagefilter() with the IMG_FILTER_SMOOTH argument.

imagefilter($im, IMG_FILTER_SMOOTH,100);

Upvotes: 2

Related Questions