PHPackages                             marcha/imagecow - 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. marcha/imagecow

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

marcha/imagecow
===============

PHP library to manipulate and generate responsive images

v1.3.1(11y ago)098MITPHPPHP &gt;=5.3.0

Since Dec 4Pushed 10y ago1 watchersCompare

[ Source](https://github.com/marcha/imagecow)[ Packagist](https://packagist.org/packages/marcha/imagecow)[ Docs](https://github.com/oscarotero/imagecow/)[ RSS](/packages/marcha-imagecow/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (12)Used By (0)

Imagecow
========

[](#imagecow)

[![Build Status](https://camo.githubusercontent.com/9a6777b13529f55305a1034b25a52951020f59045279c7f95785ad6538f4200c/68747470733a2f2f7472617669732d63692e6f72672f6f736361726f7465726f2f696d616765636f772e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/oscarotero/imagecow)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ee7043263e6c1e7243d31ebb56c8a48cae79145f364b058a7e41b407e3c320f2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f736361726f7465726f2f696d616765636f772f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/oscarotero/imagecow/?branch=master)

Created by Oscar Otero

What is Imagecow?
-----------------

[](#what-is-imagecow)

It's a php library to manipulate images to web.

- Written in PHP 5.3
- Use GD2 or Imagick libraries (and can be extended with more)
- Has an optional client-side javascript to generate responsive images
- Very simple and easy to use. There is not a lot of features, just only the basics: crop, resize, resizeCrop, etc.
- Use the PSR-4 autoloader standard

Notes on 1.x version
--------------------

[](#notes-on-1x-version)

The API in 1.x version changes a little bit (not much, only on create the instances).

How use it?
-----------

[](#how-use-it)

Use the static function Imagecow\\Image::create() to load an image and returns an imageCow instance. This function has two arguments:

- image: The image file path or a binary string with the image data
- library: The library used (Gd or Imagick). If it's not provided, it's detected automatically (in order of preference: Imagick, Gd)

```
use Imagecow\Image;

//Create an Imagick instance of "my-image.jpg" file:
$image = Image::create('my-image.jpg', 'Imagick');

//Create an instance detecting the library automatically
$image = Image::create('my-image.jpg');

//Create an instance from a binary file
$data = file_get_contents('my-image.jpg');

$image = Image::create($data);

//You can use also the direct functions:
$image = Image::createFromString($data);
$image = Image::createFromFile($file);
```

#### Crop the image

[](#crop-the-image)

```
//Arguments: ($width, $height, $x = 'center', $y = 'middle');

$image->crop(200, 300); //Crops the image to 200x300px
$image->crop(200, 300, 'left', 'top'); //Crops the image to 200x300px starting from left-top
$image->crop(200, 300, 20, '50%'); //Crops the image to 200x300px starting from 20px (x) / 50% (y)
$image->crop('50%', '50%'); //Crops the image to half size
```

#### Resize the image

[](#resize-the-image)

```
//Arguments: ($width, $height = 0, $enlarge = false)

$image->resize(200, 300); //Resizes the image to max size 200x300px (keeps the aspect ratio. If the image is lower, don't resize it)
$image->resize(800, 600, 1); //Resizes the image to max size 800x600px (keeps the aspect ratio. If the image is lower enlarge it)
$image->resize(800); //Resizes the image to 800px width and calculates the height maintaining the proportion.
```

#### Resize and Crop the image

[](#resize-and-crop-the-image)

```
//Arguments: ($width, $height, $x = 'center', $y = 'middle')

$image->resizeCrop(200, 300); //Resizes and crops the image to this size.
```

#### Rotate

[](#rotate)

```
$image->rotate(90); //Rotates the image 90 degrees
$image->autoRotate(); //Rotates the image according its EXIF data.
```

#### Convert the image to other formats:

[](#convert-the-image-to-other-formats)

```
$image->format('png');
```

#### Save the image to a file

[](#save-the-image-to-a-file)

```
$image->save('my-new-image.png');

//Overwrite the image (only if has been loaded from a file)
$image->save();
```

#### Execute multiple functions (resize, crop, resizeCrop, format)

[](#execute-multiple-functions-resize-crop-resizecrop-format)

This is useful to get images transformed dinamically using get variables: image.php?transform=resize,200,300|format,png

```
$image->transform('resize,200,300|format,png');
```

#### Show the image

[](#show-the-image)

```
$image->show();
```

#### Other functions:

[](#other-functions)

```
$image->getWidth();
$image->getHeight();
$image->getMimeType();

$image->getString(); //Returns the image in a string

$image->setBackground(array(255, 255, 255)); //Set a default background used in some transformations (for example, convert a transparent png to jpg)
$image->getExifData();
$image->setCompressionQuality(80); //Define the image compression quality for jpg images
```

Responsive images
-----------------

[](#responsive-images)

Include the Imagecow.js library in the html page and execute the function Imagecow.init();

```

	Imagecow.init();

```

This function saves a cookie with the client information (width, height, connection speed). You can configurate the cookie. The default values are:

```
Imagecow.cookie_seconds = 3600*24;
Imagecow.cookie_name = 'Imagecow_detection';
Imagecow.cookie_path = '/';
```

In the server-side, use the cookie to generate the responsive operations:

```
use Imagecow\Image;

$operations = Image::getResponsiveOperations($_COOKIE['Imagecow_detection'], $_GET['transform']);

$image = Image::create();

$image->load($_GET['img'])->transform($operations)->show();
```

Now you can transform the image according with the client dimmensions. The available options are:

- max-width
- min-width
- max-height
- min-height
- width
- height

You can use the same syntax than transform, but separate the "media-query" with ";".

```
img.php?img=my_picture.png&transform=resizeCrop,800,600;max-width=400:resize,400

```

Get me the image "my\_picture.png" with resizeCrop to 800x600. If the max-width of the client side is 400, resize to 400.

Usage in PHP frameworks
-----------------------

[](#usage-in-php-frameworks)

For Laravel and PHP FuelPHP users you can use the wrapper by @kevbaldwyn:

Other utils
-----------

[](#other-utils)

IconExtractor. Class to extract the images from an .ico file and convert to png. Only for Imagick:

```
use Imagecow\Utils\IconExtractor;

$icon = new IconExtractor('favicon.ico');

//Gets the better image from the icon (quality = color_depth + (width * height))
$image = $icon->getBetterQuality();

//Do imagecow stuff
$image->resize(100)->save('my-image.png');
```

SvgExtractor. This class allows generate images from a svg file (usefull for browsers that don't support svg format):

```
use Imagecow\Utils\SvgExtractor;

$svg = new SvgExtractor('image.svg');

//Gets the image
$image = $svg->get();

//Now you can execute the imagecow methods:
$image->resize(200)->format('jpg')->save('image.jpg');
```

Maintainers:
------------

[](#maintainers)

- @oscarotero (creator)
- @eusonlito (contributor)
- @AndreasHeiberg (contributor)
- @kevbaldwyn (contributor)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 87.4% 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 ~51 days

Recently: every ~84 days

Total

11

Last Release

4037d ago

Major Versions

v0.6.0 → v1.0.02014-04-19

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3828422?v=4)[Nikola Marčić](/maintainers/marcha)[@marcha](https://github.com/marcha)

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (83 commits)")[![eusonlito](https://avatars.githubusercontent.com/u/644551?v=4)](https://github.com/eusonlito "eusonlito (5 commits)")[![marcha](https://avatars.githubusercontent.com/u/3828422?v=4)](https://github.com/marcha "marcha (4 commits)")[![kevbaldwyn](https://avatars.githubusercontent.com/u/2512883?v=4)](https://github.com/kevbaldwyn "kevbaldwyn (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

image

### Embed Badge

![Health badge](/badges/marcha-imagecow/health.svg)

```
[![Health](https://phpackages.com/badges/marcha-imagecow/health.svg)](https://phpackages.com/packages/marcha-imagecow)
```

###  Alternatives

[intervention/image

PHP Image Processing

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

Wonderfully easy on-demand image manipulation library with an HTTP based API.

2.6k51.2M116](/packages/league-glide)[liip/imagine-bundle

This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.

1.7k38.3M217](/packages/liip-imagine-bundle)[spatie/image

Manipulate images with an expressive API

1.4k54.4M138](/packages/spatie-image)[intervention/image-laravel

Laravel Integration of Intervention Image

1536.5M102](/packages/intervention-image-laravel)[intervention/gif

PHP GIF Encoder/Decoder

5720.3M9](/packages/intervention-gif)

PHPackages © 2026

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