Rounded corners on images using PHP?

女生的网名这么多〃 提交于 2019-12-01 13:39:31

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;" />

This script shows how to apply rounded corners to images using PHP and GD Library. It is as simple as drawing four quadrants of a circle over the four corners of the image. The circle itself has to be transparent.

This script, on the other hand, generates rounded corner graphics for HTML or CSS based solutions. It generates the four corners that you can overlay over an image using CSS positioning or HTML tables.

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.

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);

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.

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!