PHP Classes
elePHPant
Icontem

Image Editor: Create or edit images from files

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2014-05-20 (1 year ago) RSS 2.0 feedNot yet rated by the usersTotal: 542 All time: 5,147 This week: 1,256Up
Version License PHP version Categories  
image-editor 1.0.2GNU Lesser Genera...5.2.1Graphics
Description Author  

This class can create or edit images from files.

It can create a new image of a given size or load an image from a given file in the formats: JPEG, PNG, GIF, WBMP and BMP.

The class can apply several types of image manipulation operations like resizing, cropping, rotating, mirroring, and put an image inside another.

The resulting image can be saved back to file in the formats JPEG, PNG, GIF, WBMP.

Picture of wapmorgan
Name: wapmorgan is available for providing paid consulting. Contact wapmorgan .
Classes: 20 packages by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 124338 in Russian Federation Russian Federation
Week rank: 15 Up2 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 7x

Winner: 1x

Details provided by the author  
**ImageEditor** is a wrapper of gd functions.
Earlier it was working only in yii-application context, now you can use *the editor* in any application.

## Installation
* Composer package: `wapmorgan/image-editor` [[1](https://packagist.org/packages/wapmorgan/image-editor)]
* Archive: `https://github.com/wapmorgan/ImageEditor/archive/master.zip`

**How to start**:
Create from existing file or make an empty area
```php
$image = ImageEditor::createFromFile($filename);
// or
$image = ImageEditor::createWithSize($width, $height);
// or
$image = ImageEditor::createFromResource(imagecreatetruecolor(90, 90));
```

## Properties:
1. **width** - width of image
2. **height** - height of image
3. **resource** - original gd-resource of image (you can pass it directly to image-gd functions)

## Operations
### Resize && Zoom (don't cut image)
**can minimize and maximize image**:

1. **zoomWidthTo(int $size)** - changes proportionally image width to `$size`
2. **zoomHeightTo(int $size)** - changes proportionally image height to `$size`

**can only minimize image**:

1. **decreaseWidthTo(int $size)** - decreases proportionally image width to `$size`, if needed
2. **decreaseHeightTo(int $size)** - decreases proportionally image height to `$size`, if needed
3. **decreaseTo(int $size)** - decreases proportionally larger side to `$size`, if needed

**can do everything you ask it for**:

1. **resize(int $width, int $height)** - resizes an image to `$width` X `$height`

### Crop (can cut image)
1. **crop($x, $y, $x2, $y2)** - cuts a rectangular piece of image
2. **decreaseSide($side, int $size)** - deletes a piece of image from specific side. For example, if $side=top and $size=100, 100px from top will be deleted.

### Rotation && Mirroring
1. **rotate($angle, $bgColor = 0)** - rotates an image. `True` equals 90°, `False` equals -90°.
2. **horizontalFlip()** - flips an image horizontally.
3. **verticalFlip()** - flips an image vertically.

### Manipulation:
1. **appendImageTo($side, ImageEditor $appendix, int $modifiers)** - appends an image (`$appendix`) to current image at `$side` (`top|bottom|left|right`).
2. **placeImageAt($x, $y, ImageEditor $image)** - places an image atop current image at `$x` X `$y`.
3. **placeImageAtCenter(ImageEditor $image)** - places an image in the center of current image.

### Save
1. **save($filename, $format, $quality)** - saves image to disk.
Possible `$format` values: jpeg, png, gif, wbmp.
Quality is an integer value between 0 (worst) and 100 (best).

### Links
* ImageEditor repo: https://github.com/wapmorgan/ImageEditor
* ImageEditor testing script: https://github.com/wapmorgan/ImageEditor-test
* ImageEditor docs: https://github.com/wapmorgan/ImageEditor-doc
* ImageEditor class reference (API): http://wapmorgan.github.io/ImageEditor-doc/classes/ImageEditor.html
 
### Changelog

```
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| version                                        | date         | description                                                                                                            |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.6: composer fixes and ImageEditor updates | May 19, 2014 | Changed:                                                                                                               |
|                                                |              | * Method **saveToFile()** marked as depricated. Now use **save()** method instead.                                     |
|                                                |              | * Added method **tryCreateFromFile()** which returns either an ImageEditor instance (on success) or null (on failure). |
|                                                |              | * Fixed composer configuration (autoloading and requirements).                                                         |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.5: instantiation from bmp files           | May 6, 2014  | Changed:                                                                                                               |
|                                                |              | * Added function **imagecreatefrombmp**.                                                                               |
|                                                |              | * Some updates in `saveToFile()`: now you can use predefined constants like IMAGETYPE_XXX to specify output format.    |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.4: new class ImageEditorTools             | Apr 22, 2014 | Changed:                                                                                                               |
|                                                |              | * Added **ImageEditorTools.php** with `pHash()` method.                                                                |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.3: standalone using and composer.json     | Apr 22, 2014 | Changed:                                                                                                               |
|                                                |              | * Added **CComponent.php**. **ImageEditor** loads in automatically if need. (so you can use ImageEditor without yii).  |
|                                                |              | * Added **composer.json**. Packagist name: `wapmorgan/image-editor`                                                    |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| v0.0.2: a lot of changes                       | Apr 12, 2014 | Changed:                                                                                                               |
|                                                |              | * allowing clone object.                                                                                               |
|                                                |              | * returning $this in all methods.                                                                                      |
|                                                |              | * **cropSide** renamed to **decreaseSide**.                                                                            |
|                                                |              | * added **decreaseWidthTo**(), **decreaseHeightTo**() and **decreaseTo**().                                            |
|                                                |              | * **appendImageTo**() finished.                                                                                        |
|                                                |              | * **rotate()** fixed.                                                                                                  |
|                                                |              | * **added gif and wbmp** formats in saveToFile().                                                                      |
|                                                |              | * **added mirroring functions**: horizontalFlip() and verticalFlip().                                                  |
|                                                |              | * **added createFromResource** static public method.                                                                   |
|                                                |              | * **created testing script**, **added docs**.                                                                          |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
| first commit                                   | Oct 4, 2013  |                                                                                                                        |
+------------------------------------------------+--------------+------------------------------------------------------------------------------------------------------------------------+
```
  Files folder image Files  
File Role Description
Plain text file CComponent.php Class Class source
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file function.imagecreatefrombmp.php Aux. Class source
Plain text file ImageEditor.php Class Class source
Plain text file ImageEditorTools.php Class Class source
Accessible without login Plain text file README.md Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 0%Total:542All time:5,147
 This week:0This week:1,256Up