1.0.0 2015-01-07 12:00 UTC


PHP class to resize images using GD


Although, I used a version of this class in a recent project, this is really just an exercise for me to create a simple PHP class library shared through Composer and Packagist.


This package is available through Packagist with the vendor and package identifier the same as this repo.

If using Composer, in your composer.json file add:

    "require": {
        "stormwild/image-resizer": "1.0.0"


include '/path/to/ImageResizer.php';

Because this class uses namespacing, when instantiating the object, you need to either use the fully qualified namespace:

$resized = \Stormwild\ImageResizer::resizer($path, $width, $height);

Or alias it:

use \Stormwild\ImageResizer;

$resized = ImageResizer::resizer($path, $width, $height);


    // possibly in controller action
    // check if image uploaded successfully
    // get path to uploaded image
    $path = "path/to/uploaded/file.ext"; // real path to file on server
    $width = 1050;
    $height = 700;    
    $resized = ImageResizer::resize($path, $width, $height);
    if($resized) {
        // upload to cloud storage
        // get url from cloud
        // save model with reference to image url

The function resizes and replaces(updates) the uploaded file to the specified dimensions.


Credits to the many code samples on image resizing using GD on the web. In particular, I referenced the following: