2

Does anyone know how to make a image have rounded corners using a PHP script?

casperOne
  • 73,706
  • 19
  • 184
  • 253

8 Answers8

5

It can be done using php-gd, but I ended up passing that task to the browser, using CSS:

<img src="photo.jpg" width="42" height="42" alt="My cool photo" style="border-radius: 15px; -moz-border-radius: 15px;" />

Quique
  • 909
  • 10
  • 8
2

Download easyphpthumbnail.class.php from this link

from this you can resize and convert image into rounded image.

in below example image is converted into transparent circle image.

include_once('easyphpthumbnail.class.php');
$source = 'demo.jpg';
$width      =  100;
$height     =  100;    
$thumb = new easyphpthumbnail;
$thumb -> Thumbheight = $width;
$thumb -> Thumbwidth = $height;
$thumb -> Backgroundcolor = '#FFFFFF';
$thumb -> Clipcorner = array(2,50,0,1,1,1,1);
$thumb -> Maketransparent = array(1,0,'#FFFFFF',10);   
$thumb -> Createthumb($source);
Dineshaws
  • 2,065
  • 16
  • 26
1

You can look at https://www.phpcontext.com/thumbnailer/ . There's a script for creating nice rounded corner thumbs with PHP. They are antialiased too.

Mike Doe
  • 16,349
  • 11
  • 65
  • 88
0

its easy to create some rounded thumbs using php, just use Thumbnailer :)

0

There are a lot of options available, you can find them using Google. The easiest way though is using the Thumbnailer. It's as simple as two lines of code:

// make an object
$th=new Thumbnailer("your-photo.jpg");

// create a 120x90 thumb and round its corners
$th->thumbFixed(120,90)->round()->save("your-thumb.jpg");

Fun it is, isn't it? :) There are a lot of other options available. The corners will be antialiased.

0

Instead of modifying the image, why not just wrap it in some HTML that has images at each corner that overlay the original to provide the appearance of rounded corners?

By doing the image editing in your .php script, you're going to put undue load on your web server, and that means your application won't scale well.

slacy
  • 11,397
  • 8
  • 56
  • 61
0

GD is great for image manipulation, but it would be much easier for you and much easier on your server if you used CSS.

Here's a great tutorial for some cool image effects using CSS:

http://www.webdesignerwall.com/tutorials/css-decorative-gallery/

For modern browsers, you can do it in pure CSS:

http://www.css3.info/preview/rounded-border/

A couple of other noteworthy ones:

http://www.spiffycorners.com/

http://www.html.it/articoli/niftycube/index.html

ryonlife
  • 6,563
  • 14
  • 51
  • 64
  • 1
    Depends on the use case. If he needs an image i.e. for a PWA App Icon you cannot use CSS. – dns_nx Dec 28 '20 at 22:17
0

It seems most or all of the libraries referenced in the other answers here are now dead and gone for one reason or other.

After some exploring, I settled on claviska/SimpleImage as a good library for rounded rectangles (and lots of other handy stuff!)

John Rix
  • 6,271
  • 5
  • 40
  • 46