Pages

Thursday 3 January 2013

How to Generate Thumbnail Image with Rounded Corners using PHP Script?

How to Generate Thumbnail Image with Rounded Corners using PHP Script?

Thumbnail Images with rounded corners are very common. You might see images with rounded corners on various websites when you browse around the web. If you are a PHP developer, generating Thumbnail Images with Rounded Corners is very easy using PHP script. There are lot of libraries available in PHP which will help you generating thumbnail images with rounded corners.

We are going to use simple PHP script library called phpThumb() to generate thumbnail images with rounded corners. phpThumb() uses the GD library to create thumbnails from images (JPEG, PNG, GIF, BMP, etc) on the fly. The output size is configurable (can be larger or smaller than the source), and the source may be the entire image or only a portion of the original image.

Following is the step by step demonstration on how to generate thumbnail images with rounded corners using PHP script?

Step 1: Download phpThumb() library from Sourceforge:


Extract the file and keep it in your Library Folder or wherever you want in your application folder.

Step 2: Now use the above library in the img tag of your images like this:

<img src="phpThumb.php?src=myImage.jpg&w=200&h=150&fltr[]=ric|20|20&f=png" />

Explanation of above img tag attributes:

1. src is the relative path to image file to phpThumb.php

2. w & h are width and height of the resulting thumbnail

3. fltr is used to tell phpThumb to generate rounded corner thumbnail with first numeric value as horizontal radius of the rounded corner and second as vertical radius in pixels.

4. The last parameter f is used to control the output image format of the thumbnail, namely png, jpg or gif. We are using png as it can render images with transparent corners which can be used on any background.

Thats all you have to do to generate thumbnail images with rounded corners using PHP script.

No comments:

Post a Comment