PHPackages                             mothership-ec/cog-imageresize - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. mothership-ec/cog-imageresize

AbandonedLibrary[Image &amp; Media](/categories/media)

mothership-ec/cog-imageresize
=============================

Dynamic URI-based image resize functionality for Cog

2.0.1(10y ago)12.5k1[8 issues](https://github.com/mothership-ec/cog-imageresize/issues)3GPL-3.0+PHPPHP &gt;=5.4.0

Since Jan 10Pushed 10y ago4 watchersCompare

[ Source](https://github.com/mothership-ec/cog-imageresize)[ Packagist](https://packagist.org/packages/mothership-ec/cog-imageresize)[ Docs](http://mothership.ec)[ RSS](/packages/mothership-ec-cog-imageresize/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (2)Versions (9)Used By (3)

Image Resize
============

[](#image-resize)

Resize Class and Controller
---------------------------

[](#resize-class-and-controller)

The Resizer can be accessed using the service `image.resize`:

```
$this->get('image.resize')->resize($url);

```

The Resize-class has two important methods:

- **generateUrl($url, $width, $height)** - Generates a url consisting of the file-name, width, height and a hash which will be the later location of the file. The $url is the publically accessible path to the image we want to resize. Urls generated by this method could look something like this: `resize_directory/test_AUTOx400-de46b9.jpg`
- **resize($url)** - Does the actual resizing, returns the resized file and saves it in the location defined by $url. The $url passed in is a the url generated by generateUrl().

This means, when we have an image called `test.jpg`, which is saved in `cog:://public/files`, this is how we could resize it:

```
$resizer = $this->get('image.resize');
$url = $resizer->generateUrl('/files/test.jpg', null, 400); // you can leave out either height or width!
$resizedImg = $resizer->resize($url);

```

We go the way of generating the url because that allows us to controll the behaviour with a controller: When we want to render a resized image in a view, we can pass in the generated `$url` as `src`-attribute. What will happen is, the first time the image is requested, the router will call the image resize controller, which will resize the image, save it to the new destination and return the image. After that the image already exists and can requested as any other image.

This is handy especially when used together with the twig extension.

Twig Extension
--------------

[](#twig-extension)

There are two methods which allow us to access the `generateUrl()`-method the `ImageResize\Resize`-class provides:

- **getResizedUrl(ResizableInterface $file, $width, $height)** - Returns the result of `Resizer::generateUrl` using the `getUrl()`-method the ResizableInterface defines:

    ```

    ```
- **getResizedImage(ResizableInterface $file, $width, $height, $attributes = array())** - Returns the rendered ``-tag including `src`, `width`, `height`, `alt`(using ResizableInterface's `getAltText()`-method) and additional attributes using the `$attributes`-array:

    ```
      {# file->getUrl() = '/test.jpg' #}
      {# file->getAltText() = 'test' #}

      {{ getResizedImage(file, 500, 200, {'class': 'file'}) }}

    ```

    Which will render

    ```

    ```

    If the $attributes-array provides an `alt`-attribute, instead of using file's `getAltText()` to determine the alt-text, `$attributes['alt']` will be shown:

    ```
      {{ getResizedImage(file, 500, 200, {'alt': 'abcabc'}) }}

    ```

    This will return this:

    ```

    ```

Default Image
-------------

[](#default-image)

If the `$url` passed to the `resize`-method is not the path to an existing file in the system, a default-image is resized instead.

This default image can be configured in `config/app.yml`:

```
image-resize:
	default-image-path: cogules/MyApp:SetUp/images/default.png

```

The `generateUrl` method looks up the file and if it doesn't exist it returns the url to the default image. That way only one image for each size is generated and the correct resized image can be generated as soon as a file is uploaded to the server.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~125 days

Recently: every ~156 days

Total

6

Last Release

3878d ago

Major Versions

1.1.0 → 2.0.02015-02-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c80abec1ec847de90ada27e2239c31f4374ed1d91912493f5415a688c269a78?d=identicon)[thomasjthomasj](/maintainers/thomasjthomasj)

---

Top Contributors

[![thomasjthomasj](https://avatars.githubusercontent.com/u/4520924?v=4)](https://github.com/thomasjthomasj "thomasjthomasj (12 commits)")[![joeholdcroft](https://avatars.githubusercontent.com/u/2511043?v=4)](https://github.com/joeholdcroft "joeholdcroft (2 commits)")[![kuiche](https://avatars.githubusercontent.com/u/5089510?v=4)](https://github.com/kuiche "kuiche (1 commits)")

---

Tags

thumbnailimageresize

### Embed Badge

![Health badge](/badges/mothership-ec-cog-imageresize/health.svg)

```
[![Health](https://phpackages.com/badges/mothership-ec-cog-imageresize/health.svg)](https://phpackages.com/packages/mothership-ec-cog-imageresize)
```

###  Alternatives

[intervention/image

PHP Image Processing

14.3k194.3M2.2k](/packages/intervention-image)[sybio/image-workshop

Powerful PHP class using GD library to work easily with images including layer notion (like Photoshop or GIMP)

860918.1k11](/packages/sybio-image-workshop)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M102](/packages/intervention-image-laravel)[jbzoo/image

A PHP class that simplifies working with images

171126.9k3](/packages/jbzoo-image)[stefangabos/zebra_image

A single-file, lightweight PHP library designed for efficient image manipulation featuring methods for modifying images and applying filters

141110.4k6](/packages/stefangabos-zebra-image)[coldume/imagecraft

A reliable and extensible PHP image manipulation library

10133.7k2](/packages/coldume-imagecraft)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
