Tuesday 5 August 2014

How to Resize Image Dynamically in PHP

How to Resize Image Dynamically in PHP

There is an extremely useful PHP library called timthumb which comes very handy. It’s just a simple PHP script that you need to download and put in some folder under your website. And then simply call it with appropriate arguments.






  • Download timthumb.php and put under any folder.
  • Upload this script timthumb.php though FTP to your web hosting. Put it under a directory /script.
  • Just call timthumb.php with appropriate arguments, For example:
    <img src="/script/timthumb.php?src=/some/path/myimage.png&w=100&h=80"
        alt="resized image" />

    And that’s all!!


  • One thing worth noting here is that this library will create a folder cache in the directory where timthumb.php script resides. This folder will cache the resized image for better performance.

    You can refer following table for different parameters and its meaning.

    ParameterValuesMeaning
    srcsourceurl to imageTells TimThumb which image to resize
    wwidththe width to resize toRemove the width to scale proportionally (will then need the height)
    hheightthe height to resize toRemove the height to scale proportionally (will then need the width)
    qquality0 – 100Compression quality. The higher the number the nicer the image will look. I wouldn’t recommend going any higher than about 95 else the image will get too large
    aalignmentc, t, l, r, b, tl, tr, bl, brCrop alignment. c = center, t = top, b = bottom, r = right, l = left. The positions can be joined to create diagonal positions
    zczoom / crop0, 1, 2, 3Change the cropping and scaling settings
    ffilterstoo many to mentionLet’s you apply image filters to change the resized picture. For instance you can change brightness/ contrast or even blur the image
    ssharpenApply a sharpen filter to the image, makes scaled down images look a little crisper
    cccanvas colourhexadecimal colour value (#ffffff)Change background colour. Most used when changing the zoom and crop settings, which in turn can add borders to the image.
    ctcanvas transparencytrue (1)Use transparency and ignore background colour



    Hope this is useful for you :)

    No comments:

    Post a Comment

    List OF BANK PAN Numbers

    List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...