Please note, this is a STATIC archive of website www.thewebhelp.com from 28 Sep 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Create square image thumbnail with PHP

Sometimes listing more images and align them properly in your list or layout might not be so easy, because the images very often have different sizes and proportions; A good solution is to create square images with same proportions.

With this function you can create a square thumbnail of an original image by a simple code like this:

create_square_image("sample.jpg","sample_thumb.jpg",200);

Image to square thumbnail

  • First parameter is the name of the image file to resize (can be jpg, gif, png).
  • Second parameter is the path where you would like to save the new square thumb, e.g. "sample_thumb.jpg" or just "NULL" if you do not want to save new image.
    Folder whre you save image has to be writable, "777" permission code on most servers.
  • 200 is the size of the new square thumbnail.

Optionally ...

If you just want to display the generated thumb file and not save an actual smaller file on server, then the second parameter should be "NULL" and in your html page have the image resize script as the img src, for example:

<img src="image_resize.php" />

And inside image_resize.php have the resize function and then:
create_square_image("sample.jpg",NULL,200);

Download php square thumb script.

Rate this content; the results will appear next to article links in site:
You need flash player