May 19, 2013
0 0

Image Resize Component for CakePHP

Written by

Hi my friends. Every CakePHP developer googling several times to find an Image resize component for their development . Here I tried to give them a solution . I used it in several times in several apps , though the main logic I found on google after that I made it for CakePHP. Please check the attached zip to include and source code.

And one most important things is that image resize should be maintained aspect ratio. In the source code you will find that a component called “Image” which I import in a function of a Controller. After that initialize the component like

$MyImageCom = new ImageComponent();

Now prepare the image for re-sizing , assume that your image already store in “img” , member folder under “webroot” and the name store in $imagename , like $imagename=”abc.jpg” . Now you can resize it by calling the function “resize” with width , height even you can set the background color from here by given RGB code. Now tell the component to save to the particular path by calling “save” function with the full path of the new image name. With the above you can resize a single picture with multiple size. That’s it buddy.


Here is the source code:

App::import('Component', 'Image');
$MyImageCom = new ImageComponent();




Here I attached an example source code for your reference. Please feel free to contact me if you found anything wrong or need any help. I always try to be responsive as soon as possible.

Download Source code:Here

Share this:
Article Categories:
CakePHP · Web Development

Comments to Image Resize Component for CakePHP

  • thank you very much

    lamin September 19, 2013 5:11 am Reply
  • Is before save, the image name should change , or we can keep the old image name for saving image?

    Farman December 17, 2013 5:01 pm Reply
  • Thanks.You Are Saviour..

    parmjeet February 7, 2014 6:49 pm Reply
    • Thanks , we will try to update it regularly.

      Bivash Kanti Pal February 10, 2014 8:51 am Reply
  • Another Component that to Resize images in Cakephp is RedimensionaComponent. The use is easy, and you can find images in directories.

    willqlm September 19, 2014 5:32 am Reply
    • Hi Will,
      It’s great , thanks for sharing your tutorial . Keep it up bro.
      Blog For Developer Team Member

      Bivash Kanti Pal September 19, 2014 9:02 am Reply
  • Thanks Bivash

    I have helped in something….

    willqlm September 24, 2014 10:50 pm Reply
  • Hi there, i study your blog occasionally andd i personal a similar
    one and i was just curious if you get lots of spam comments?
    If so how do you reduce it, any plugin or anything you may suggest?
    I get so much lately it’s driving me insane so any help is very
    much appreciated.

    cheap jordans November 30, 2014 2:27 am Reply
  • Thanks very much

    i would like to suggest you add a demo link of it.It will helpfull for every one who want to use it.

    Narinder singh March 3, 2015 10:51 am Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

Result of *

Social Widgets powered by