1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-07-31 13:40:08 +02:00

prepare to tag v0.5

This commit is contained in:
Mikael Roos
2014-02-12 14:45:25 +01:00
parent 7478b12751
commit 20a621bf48
22 changed files with 1916 additions and 1286 deletions

2433
CImage.php

File diff suppressed because it is too large Load Diff

115
README.md
View File

@@ -4,11 +4,9 @@ Image conversion on the fly using PHP
About
-------------------------------------
`CImage` is a PHP class which enables scaling, cropping, filtering effects and processing of images using PHP GD. The script `img.php` uses `CImage` to enable server-side image processing together with caching and optimization of the processed images.
`CImage` is a PHP class which enables resizing of images through scaling and cropping together with filtering effects, all using PHP GD. The script `img.php` uses `CImage` to enable server-side image processing together with caching and optimization of the processed images.
Server-side image processing is a useful tool for any web developer, `img.php` has an easy to use interface and its quite powerful when you integrate it with your website. This is a most useful tool for any web developer who has a need to create and process images for a website.
This is free software and open source.
Server-side image processing is a most useful tool for any web developer, `img.php` has an easy to use interface and its quite powerful when you integrate it with your website. Using it might decrease the time and effort put in managing images and improve your work flow when creating content for websites.
Read more on http://dbwebb.se/opensource/cimage
@@ -17,22 +15,23 @@ Enjoy!
Mikael Roos (me@mikaelroos.se)
License
-------------------------------------
License according to MIT.
This is free software and open source software, licensed according MIT.
Installation and get going
-------------------------------------
**Latest stable version is v0.4.1 released 2014-01-27.**
**Latest stable version is v0.5 released 2014-02-11.**
```bash
git clone git://github.com/mosbth/cimage.git
cd cimage
git checkout v0.4.1
git checkout v0.5
```
Make the cache-directory writable by the webserver.
@@ -41,48 +40,110 @@ Make the cache-directory writable by the webserver.
chmod 777 cache
```
Try it out by pointing your browser to the test file `test.php`.
Try it out by pointing your browser to the test file `webroot/test.php`.
Review the settings in `webroot/img_config.php` and check out `webroot/img.php` on how it uses `CImage`.
Review the settings in `img.php`.
Usage
-------------------------------------
###List of parameters {#parameters}
The `img.php` supports a lot of parameters. Combine the parameters to get the desired behavior and resulting image. For example, take the original image, resize it using width, aspect-ratio and crop-to-fit, apply a sharpen effect, save the image as JPEG using quality 30.
| `img.php?src=kodim13.png&w=600&aspect-ratio=4&crop-to-fit&sharpen&save-as=jpg&q=30` |
|-----------------------------------------------------------|
| <img src=/kod-exempel/cimage_/webroot/img.php?src=kodim13.png&w=600&aspect-ratio=4&crop-to-fit&sharpen&save-as=jpg&q=30 alt=''> |
Here is a list of all parameters that you can use together with `img.php`, grouped by its basic intent of usage.
####Mandatory options and debugging
The `src` is the only mandatory option. The other in this section is useful for debugging or deciding what version of the target image is used.
| Parameter | Explained |
|----------------|----------------------------------------------|
| `src` | `src=img.png` choses the source image to use. |
| `h, height` | `h=200` sets the width to be to max 200px. `h=25%` sets the height to 25% of its original height. |
| `w, width` | `w=200` sets the height to be max 200px. `w=100%` sets the width to 100% of its original width. |
| `ar, aspect-ratio` | Use this as aspect ratio. Use together with either height or width or alone to base calculations on original image dimensions. This setting is used to calculate the resulting dimension for the image. `w=160&aspect-ratio=1.6` results in a width of 100px. |
| `s, scale` | Scale the image to a size proportional to a percentage of its original size, `scale=25` makes a image 25% of its original size and `size=200` doubles up the image size. Scale is applied before all processing and has no impact of the final width and height. |
| `nr, no-ratio, stretch` | Do *not* keep aspect ratio when resizing using both width & height constraints. Results in stretching the image, if needed, to fit in the resulting box. |
| `src` | Source image to use, mandatory. `src=img.png` or with subdirectory `src=dir/img.png`. |
| `nc, no-cache` | Do not use the cached version, do all image processing and save a new image to cache. |
| `so, skip-original`| Skip using the original image, always process image, create and use a cached version of the original image. |
| `v, verbose` | Do verbose output and print out a log what happens. Good for debugging, analyzing the process and inspecting how the image is being processed. |
####Options for resizing image
These options are all affecting the dimensions used when resizing the image. Its used to define the area to use in the source image and the resulting dimensions for the target image.
| Parameter | Explained |
|----------------|----------------------------------------------|
| `h, height` | `h=200` sets the width to be to max 200px. `h=25%` sets the height to max 25% of its original height. |
| `w, width` | `w=200` sets the height to be max 200px. `w=100%` sets the width to max 100% of its original width. |
| `ar, aspect-ratio` | Control target aspect ratio. Use together with either height or width or alone to base calculations on original image dimensions. This setting is used to calculate the resulting dimension for the image. `w=160&aspect-ratio=1.6` results in a height of 100px. Use ar=!1.6 to inverse the ratio, useful when using portrat instead of landscape images. |
| `nr, no-ratio, stretch` | Do *not* keep aspect ratio when resizing and using both width & height constraints. Results in stretching the image, if needed, to fit in the resulting box. |
| `cf, crop-to-fit` | Set together with both `h` & `w` to make the image fit into dimensions, and crop out the rest of the image. |
| `a, area` | Define the area of the image to work with. Set `area=10,10,10,10` (top,right,bottom,left) to crop out the 10% of the outermost area. It works like an offset to define which part of the image you want to process. Its an alternative to use `crop`. |
| `c, crop` | Crops an area from the original image, set width, height, start_x and start_y to define the area to crop, for example `crop=100,100,10,10` (`crop=width,height,start_x,start_y`). Left top corner is 0, 0. You can use left, right or center when setting start_x. You may use top, bottom or center when setting start_y. You can use negative values for x and y. Use 0 for width or height to get the width/height of the original image. Use negative values for width/height to get original width/height minus selected value. |
| `q, quality` | Quality affects lossy compression and file size for JPEG images by setting the quality between 1-100, default is 60. Quality has no effect on PNG or GIF. |
| `d, deflate` | For PNG images it defines the compression algorithm, values can be 1-9, default is defined by PHP GD. Quality has no effect on JPEG or GIF. |
| `a, area` | Define the area of the image to work with. Set `area=10,10,10,10` (top,right,bottom,left) to crop out the 10% of the outermost area. It works like an offset to define which part of the image you want to process. Its an alternative of using `crop`. |
| `c, crop` | Crops an area from the original image, set width, height, start_x and start_y to define the area to crop, for example `crop=100,100,10,10` (`crop=width,height,start_x,start_y`). Left top corner is 0, 0. You can use `left`, `right` or `center` when setting start_x. You may use `top`, `bottom` or `center` when setting start_y. |
####Processing of image before resizing
These options are executed *before* the image is resized.
| Parameter | Explained |
|----------------|----------------------------------------------|
| `s, scale` | Scale the image to a size proportional to a percentage of its original size, `scale=25` makes an image 25% of its original size and `size=200` doubles up the image size. Scale is applied before resizing and has no impact of the target width and height. |
####Processing of image after resizing
These options are executed *after* the image is resized.
| Parameter | Explained |
|----------------|----------------------------------------------|
| `sharpen` | Appy a filter that sharpens the image. |
| `emboss` | Appy a filter with an emboss effect. |
| `blur` | Appy a filter with a blur effect. |
| `f, filter` | Apply filter to image, `f=colorize,0,255,0,0` makes image more green. Supports all filters as defined in [PHP GD `imagefilter()`](http://php.net/manual/en/function.imagefilter.php). |
| `f0, f1-f9` | Same as `filter`, just add more filters. Applied in order `f`, `f0-f9`. |
| `p, palette` | Create a palette version of the image with up to 256 colors. |
| `sa, save-as` | Save resulting image as JPEG, PNG or GIF, for example `?src=river.png&save-as=gif`. |
| `nc, no-cache` | Do not use the cached version, do all image processing and save a new image to cache. |
| `so, skip-original`| Skip using the original image, always process image, create and use a cached version of the original image. |
| `v, verbose` | Do verbose output and print out a log what happens. Good for debugging, analyzing what happens or analyzing the image being processed. |
Combine the parameters to get the desired behavior and resulting image. For example, take the original image, resize it, apply a sharpen effect, save the image as JPEG and use quality 30.
`img.php?src=kodim13.png&w=600&sharpen&save-as=jpg&q=30`
####Saving image, affecting quality and filesize
Options for saving the target image.
| Parameter | Explained |
|----------------|----------------------------------------------|
| `q, quality` | Quality affects lossy compression and file size for JPEG images by setting the quality between 1-100, default is 60. Quality only affects JPEG. |
| `co, compress` | For PNG images it defines the compression algorithm, values can be 0-9, default is defined by PHP GD. Compress only affects PNG. |
| `p, palette` | Create a palette version of the image with up to 256 colors. |
| `sa, save-as` | Save resulting image as JPEG, PNG or GIF, for example `?src=river.png&save-as=gif`. |
Revision history
-------------------------------------
v0.5 (2014-02-07)
* Change constant name `CImage::PNG_QUALITY_DEFAULT` to `CImage::PNG_COMPRESSION_DEFAULT`.
* Split JPEG quality and PNG compression, `CImage->quality` and `CImage->compression`
* Changed `img.php` parameter name `d, deflate` to `co, compress`.
* Separating configuration issues from `img.php` to `img_config.php`.
* Format code according to PSR-2.
* Disabled post-processing JPEG and PNG as default.
* This version is supporting PHP 5.3, later versions will require 5.5 or later.
* Using GitHub issue tracking for feature requests and planning.
* Rewrote [the manual](http://dbwebb.se/opensource/cimage).
v0.4.1 (2014-01-27)
* Changed => to == on Modified-Since.
@@ -145,5 +206,5 @@ v0.1 (2012-04-25)
<pre>
.
..: Copyright 2012-2013 by Mikael Roos (me@mikaelroos.se)
..: Copyright 2012-2014 by Mikael Roos (me@mikaelroos.se)
</pre>

1
cache/README.md vendored
View File

@@ -1 +0,0 @@
This directory must be writable by the webserver.

196
img.php
View File

@@ -1,196 +0,0 @@
<?php
/**
* Resize images on the fly using cache.
*
* @author Mikael Roos mos@dbwebb.se
* @example http://dbwebb.se/kod-exempel/cimage/
* @link https://github.com/mosbth/cimage
*
*/
error_reporting(-1);
set_time_limit(20);
// Do some sanity checks
function errorPage($msg) {
header("Status: 404 Not Found");
die('404: ' . $msg);
}
// Custom exception handler
function myExceptionHandler($exception) {
errorPage("<p><b>img.php: Uncaught exception:</b> <p>" . $exception->getMessage() . "</p><pre>" . $exception->getTraceAsString(), "</pre>");
}
set_exception_handler('myExceptionHandler');
// Use preprocessing of images
define('PNG_FILTER', '/usr/local/bin/optipng -q');
define('PNG_DEFLATE', '/usr/local/bin/pngout -q');
define('JPEG_OPTIMIZE', '/usr/local/bin/jpegtran -copy none -optimize');
// Append ending slash
$cimageClassFile = __DIR__.'/CImage.php'; // Where is the class file
$pathToImages = __DIR__.'/img/'; // Where are the image base directory
$pathToCache = __DIR__.'/cache/'; // Where is the cache directory
$gridColumnWidth = 30;
$gridGutterWidth = 10;
$gridColumns = 24;
// settings for do not largen smaller images
// settings for max image dimensions
$maxWidth = $maxHeight = 2000;
$maxScale = 400;
// Set sizes to map constant to value, easier to use with width or height
$sizes = array(
'w1' => 613,
'w2' => 630,
);
// Predefine some common aspect ratios
$aspectRatios = array(
'3:1' => 3/1,
'3:2' => 3/2,
'4:3' => 4/3,
'8:5' => 8/5,
'16:10' => 16/10,
'16:9' => 16/9,
'golden' => 1.618,
);
// Add column width to $area, useful for use as predefined size for width (or height).
for($i = 1; $i <= $gridColumns; $i++) {
$sizes['c' . $i] = ($gridColumnWidth + $gridGutterWidth) * $i - $gridGutterWidth;
}
// Get input from querystring
$srcImage = isset($_GET['src']) ? $_GET['src'] : null;
$newWidth = isset($_GET['width']) ? $_GET['width'] : (isset($_GET['w']) ? $_GET['w'] : null);
$newHeight = isset($_GET['height']) ? $_GET['height'] : (isset($_GET['h']) ? $_GET['h'] : null);
$aspectRatio = isset($_GET['aspect-ratio']) ? $_GET['aspect-ratio'] : (isset($_GET['ar']) ? $_GET['ar'] : null);
$scale = isset($_GET['scale']) ? $_GET['scale'] : (isset($_GET['s']) ? $_GET['s'] : null);
$area = isset($_GET['area']) ? $_GET['area'] : (isset($_GET['a']) ? $_GET['a'] : null);
$crop = isset($_GET['crop']) ? $_GET['crop'] : (isset($_GET['c']) ? $_GET['c'] : null);
$quality = isset($_GET['quality']) ? $_GET['quality'] : (isset($_GET['q']) ? $_GET['q'] : null);
$deflate = isset($_GET['deflate']) ? $_GET['deflate'] : (isset($_GET['d']) ? $_GET['d'] : null);
$saveAs = isset($_GET['save-as']) ? $_GET['save-as'] : (isset($_GET['sa']) ? $_GET['sa'] : null);
$sharpen = isset($_GET['sharpen']) ? true : null;
$emboss = isset($_GET['emboss']) ? true : null;
$blur = isset($_GET['blur']) ? true : null;
$palette = isset($_GET['palette']) || isset($_GET['p']) ? true : false;
$verbose = isset($_GET['verbose']) || isset($_GET['v']) ? true : false;
$useCache = isset($_GET['no-cache']) || isset($_GET['nc']) ? false : true;
$useOriginal = isset($_GET['skip-original']) || isset($_GET['so']) ? false : true;
$keepRatio = isset($_GET['no-ratio']) ? false : (isset($_GET['nr']) ? false : (isset($_GET['stretch']) ? false : true ));
$cropToFit = isset($_GET['crop-to-fit']) ? true : (isset($_GET['cf']) ? true : false);
// Check to replace predefined size
if(isset($sizes[$newWidth])) {
$newWidth = $sizes[$newWidth];
}
if(isset($sizes[$newHeight])) {
$newHeight = $sizes[$newHeight];
}
// Check to replace predefined aspect ratio
$negateAspectRatio = ($aspectRatio[0] == '!') ? true : false;
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
if(isset($aspectRatios[$aspectRatio])) {
$aspectRatio = $aspectRatios[$aspectRatio];
}
if($negateAspectRatio) {
$aspectRatio = 1 / $aspectRatio;
}
// Add all filters to an array
$filters = array();
$filter = isset($_GET['filter']) ? $_GET['filter'] : (isset($_GET['f']) ? $_GET['f'] : null);
if($filter) { $filters[] = $filter; }
for($i=0; $i<10;$i++) {
$filter = isset($_GET["filter{$i}"]) ? $_GET["filter{$i}"] : (isset($_GET["f{$i}"]) ? $_GET["f{$i}"] : null);
if($filter) { $filters[] = $filter; }
}
// Santize and check domain for incoming parameters. (Move to CImage)
isset($srcImage) or errorPage('Must set src-attribute.');
preg_match('#^[a-z0-9A-Z-/_\.]+$#', $srcImage) or errorPage('Filename contains invalid characters.');
is_file($pathToImages . '/' . $srcImage) or errorPage('Imagefile does not exists.');
is_writable($pathToCache) or errorPage('Cache-directory does not exists or is not writable.');
is_null($quality) or ($quality > 0 and $quality <= 100) or errorPage('Quality out of range');
is_null($deflate) or ($defalte > 0 and $deflate <= 9) or errorPage('Deflate out of range');
is_null($scale) or ($scale >= 0 and $quality <= 400) or errorPage('Scale out of range');
is_null($aspectRatio) or is_numeric($aspectRatio) or errorPage('Aspect ratio out of range');
// width
if($newWidth[strlen($newWidth)-1] == '%') {
is_numeric(substr($newWidth, 0, -1)) or errorPage('Width % out of range.');
}
else {
is_null($newWidth) or ($newWidth > 10 && $newWidth <= $maxWidth) or errorPage('Width out of range.');
}
// height
if($newHeight[strlen($newHeight)-1] == '%') {
is_numeric(substr($newHeight, 0, -1)) or errorPage('Height % out of range.');
}
else {
is_null($newHeight) or ($newHeight > 10 && $newHeight <= $maxHeight) or errorPage('Hight out of range.');
}
// Display image if verbose mode
if($verbose) {
$query = array();
parse_str($_SERVER['QUERY_STRING'], $query);
unset($query['verbose']);
unset($query['v']);
unset($query['nocache']);
unset($query['nc']);
$url1 = '?' . http_build_query($query);
echo <<<EOD
<a href=$url1><code>$url1</code></a><br>
<img src='{$url1}' />
EOD;
}
// Create and output the image
require($cimageClassFile);
$img = new CImage($srcImage, $pathToImages, $pathToCache);
$img->ResizeAndOutput(array(
'newWidth' => $newWidth,
'newHeight' => $newHeight,
'aspectRatio' => $aspectRatio,
'keepRatio' => $keepRatio,
'cropToFit' => $cropToFit,
'scale' => $scale,
'area' => $area,
'quality' => $quality,
'deflate' => $deflate,
'crop' => $crop,
'filters' => $filters,
'verbose' => $verbose,
'useCache' => $useCache,
'useOriginal' => $useOriginal,
'saveAs' => $saveAs,
'sharpen' => $sharpen,
'emboss' => $emboss,
'blur' => $blur,
'palette' => $palette,
));

431
webroot/img.php Normal file
View File

@@ -0,0 +1,431 @@
<?php
/**
* Resize images on the fly using CImage, configuration is made in file named.
*
*/
/**
* Default configuration options, can be overridden in own config-file.
*
* @param string $msg to display.
*
* @return void
*/
function errorPage($msg)
{
header("Status: 404 Not Found");
die('img.php say 404: ' . $msg);
}
/**
* Custom exception handler.
*/
set_exception_handler(function($exception) {
errorPage("<p><b>img.php: Uncaught exception:</b> <p>" . $exception->getMessage() . "</p><pre>" . $exception->getTraceAsString(), "</pre>");
});
/**
* Get input from query string or return default value if not set.
*
* @param mixed $key as string or array of string values to look for in $_GET.
* @param mixed $default value to return when $key is not set in $_GET.
*
* @return mixed value from $_GET or default value.
*/
function get($key, $default = null)
{
if (is_array($key)) {
foreach ($key as $val) {
if (isset($_GET[$val])) {
return $_GET[$val];
}
}
} elseif (isset($_GET[$key])) {
return $_GET[$key];
}
return $default;
}
/**
* Get input from query string and set to $defined if defined or else $undefined.
*
* @param mixed $key as string or array of string values to look for in $_GET.
* @param mixed $defined value to return when $key is set in $_GET.
* @param mixed $undefined value to return when $key is not set in $_GET.
*
* @return mixed value as $defined or $undefined.
*/
function getDefined($key, $defined, $undefined)
{
return get($key) === null ? $undefined : $defined;
}
/**
* Log when verbose mode, when used without argument it returns the result.
*
* @param string $msg to log.
*
* @return void or array.
*/
function verbose($msg = null)
{
global $verbose;
static $log = array();
if (!$verbose) {
return;
}
if (is_null($msg)) {
return $log;
}
$log[] = $msg;
}
/**
* Default configuration options, can be overridden in own config-file.
*/
$config = array(
);
$configFile = __DIR__.'/'.basename(__FILE__, '.php').'_config.php';
$config = array_merge($config, require $configFile);
call_user_func($config['error_reporting']);
/**
* verbose, v - do a verbose dump of what happens
*/
$verbose = getDefined(array('verbose', 'v'), true, false);
/**
* src - the source image file.
*/
$srcImage = get('src')
or errorPage('Must set src-attribute.');
preg_match('#^[a-z0-9A-Z-/_\.]+$#', $srcImage)
or errorPage('Filename contains invalid characters.');
verbose("src = $srcImage");
/**
* width, w - set target width, affecting the resulting image width, height and resize options
*/
$newWidth = get(array('width', 'w'));
// Check to replace predefined size
$sizes = call_user_func($config['size_constant']);
if (isset($sizes[$newWidth])) {
$newWidth = $sizes[$newWidth];
}
// Support width as % of original width
if ($newWidth[strlen($newWidth)-1] == '%') {
is_numeric(substr($newWidth, 0, -1))
or errorPage('Width % not numeric.');
} else {
is_null($newWidth)
or ($newWidth > 10 && $newWidth <= $config['max_width'])
or errorPage('Width out of range.');
}
verbose("new width = $newWidth");
/**
* height, h - set target height, affecting the resulting image width, height and resize options
*/
$newHeight = get(array('height', 'h'));
// Check to replace predefined size
if (isset($sizes[$newHeight])) {
$newHeight = $sizes[$newHeight];
}
// height
if ($newHeight[strlen($newHeight)-1] == '%') {
is_numeric(substr($newHeight, 0, -1))
or errorPage('Height % out of range.');
} else {
is_null($newHeight)
or ($newHeight > 10 && $newHeight <= $config['max_height'])
or errorPage('Hight out of range.');
}
verbose("new height = $newHeight");
/**
* aspect-ratio, ar - affecting the resulting image width, height and resize options
*/
$aspectRatio = get(array('aspect-ratio', 'ar'));
// Check to replace predefined aspect ratio
$aspectRatios = call_user_func($config['aspect_ratio_constant']);
$negateAspectRatio = ($aspectRatio[0] == '!') ? true : false;
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
if (isset($aspectRatios[$aspectRatio])) {
$aspectRatio = $aspectRatios[$aspectRatio];
}
if ($negateAspectRatio) {
$aspectRatio = 1 / $aspectRatio;
}
is_null($aspectRatio)
or is_numeric($aspectRatio)
or errorPage('Aspect ratio out of range');
verbose("aspect ratio = $aspectRatio");
/**
* crop-to-fit, cf - affecting the resulting image width, height and resize options
*/
$cropToFit = getDefined(array('crop-to-fit', 'cf'), true, false);
verbose("crop to fit = $cropToFit");
/**
* no-ratio, nr, stretch - affecting the resulting image width, height and resize options
*/
$keepRatio = getDefined(array('no-ratio', 'nr', 'stretch'), false, true);
verbose("keep ratio = $keepRatio");
/**
* crop, c - affecting the resulting image width, height and resize options
*/
$crop = get(array('crop', 'c'));
verbose("crop = $crop");
/**
* area, a - affecting the resulting image width, height and resize options
*/
$area = get(array('area', 'a'));
verbose("area = $area");
/**
* skip-original, so - skip the original image and always process a new image
*/
$useOriginal = getDefined(array('save-as', 'sa'), false, true);
verbose("use original = $useOriginal");
/**
* no-cache, nc - skip the cached version and process and create a new version in cache.
*/
$useCache = getDefined(array('no-cache', 'nc'), false, true);
verbose("use cache = $useCache");
/**
* quality, q - set level of quality for jpeg images
*/
$quality = get(array('quality', 'q'));
is_null($quality)
or ($quality > 0 and $quality <= 100)
or errorPage('Quality out of range');
verbose("quality = $quality");
/**
* compress, co - what strategy to use when compressing png images
*/
$compress = get(array('compress', 'co'));
is_null($compress)
or ($compress > 0 and $compress <= 9)
or errorPage('Compress out of range');
verbose("compress = $compress");
/**
* save-as, sa - what type of image to save
*/
$saveAs = get(array('save-as', 'sa'));
verbose("save as = $saveAs");
/**
* scale, s - Processing option, scale up or down the image prior actual resize
*/
$scale = get(array('scale', 's'));
is_null($scale)
or ($scale >= 0 and $quality <= 400)
or errorPage('Scale out of range');
verbose("scale = $scale");
/**
* palette, p - Processing option, create a palette version of the image
*/
$palette = getDefined(array('palette', 'p'), true, false);
verbose("palette = $palette");
/**
* sharpen - Processing option, post filter for sharpen effect
*/
$sharpen = getDefined('sharpen', true, null);
verbose("sharpen = $sharpen");
/**
* emboss - Processing option, post filter for emboss effect
*/
$emboss = getDefined('emboss', true, null);
verbose("emboss = $emboss");
/**
* blur - Processing option, post filter for blur effect
*/
$blur = getDefined('blur', true, null);
verbose("blur = $blur");
/**
* filter, f, f0-f9 - Processing option, post filter for various effects using imagefilter()
*/
$filters = array();
$filter = get(array('filter', 'f'));
if ($filter) {
$filters[] = $filter;
}
for ($i = 0; $i < 10; $i++) {
$filter = get(array("filter{$i}", "f{$i}"));
if ($filter) {
$filters[] = $filter;
}
}
verbose("filters = " . print_r($filters, 1));
/**
* Display image if verbose mode
*/
if ($verbose) {
$query = array();
parse_str($_SERVER['QUERY_STRING'], $query);
unset($query['verbose']);
unset($query['v']);
unset($query['nocache']);
unset($query['nc']);
$url1 = '?' . http_build_query($query);
$log = htmlentities(print_r(verbose(), 1));
echo <<<EOD
<a href=$url1><code>$url1</code></a><br>
<img src='{$url1}' />
<pre>$log</pre>
EOD;
}
/**
* Create and output the image
*/
require $config['cimage_class'];
$img = new CImage();
$img->setVerbose($verbose)
->setSource($srcImage, $config['image_path'])
->setOptions(
array(
// Options for calculate dimensions
'newWidth' => $newWidth,
'newHeight' => $newHeight,
'aspectRatio' => $aspectRatio,
'keepRatio' => $keepRatio,
'cropToFit' => $cropToFit,
'crop' => $crop,
'area' => $area,
// Pre-processing, before resizing is done
'scale' => $scale,
// Post-processing, after resizing is done
'palette' => $palette,
'filters' => $filters,
'sharpen' => $sharpen,
'emboss' => $emboss,
'blur' => $blur,
)
)
->initDimensions()
->calculateNewWidthAndHeight()
->setSaveAsExtension($saveAs)
->setJpegQuality($quality)
->setPngCompression($compress)
->useOriginalIfPossible($useOriginal)
->generateFilename($config['cache_path'])
->useCacheIfPossible($useCache)
->load()
->preResize()
->resize()
->postResize()
->setPostProcessingOptions($config['postprocessing'])
->save()
->output();

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 245 KiB

After

Width:  |  Height:  |  Size: 245 KiB

View File

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

View File

Before

Width:  |  Height:  |  Size: 622 KiB

After

Width:  |  Height:  |  Size: 622 KiB

View File

Before

Width:  |  Height:  |  Size: 544 KiB

After

Width:  |  Height:  |  Size: 544 KiB

View File

Before

Width:  |  Height:  |  Size: 770 KiB

After

Width:  |  Height:  |  Size: 770 KiB

View File

Before

Width:  |  Height:  |  Size: 803 KiB

After

Width:  |  Height:  |  Size: 803 KiB

View File

Before

Width:  |  Height:  |  Size: 589 KiB

After

Width:  |  Height:  |  Size: 589 KiB

View File

Before

Width:  |  Height:  |  Size: 684 KiB

After

Width:  |  Height:  |  Size: 684 KiB

View File

Before

Width:  |  Height:  |  Size: 544 KiB

After

Width:  |  Height:  |  Size: 544 KiB

View File

Before

Width:  |  Height:  |  Size: 681 KiB

After

Width:  |  Height:  |  Size: 681 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

@@ -11,9 +11,9 @@ return array(
* Paths, where are all the stuff I should use?
* Append ending slash on directories.
*/
'cimage_class' => __DIR__.'/CImage.php',
'cimage_class' => __DIR__.'/../CImage.php',
'image_path' => __DIR__.'/img/',
'cache_path' => __DIR__.'/cache/',
'cache_path' => __DIR__.'/../cache/',
@@ -94,27 +94,5 @@ return array(
error_reporting(-1);
set_time_limit(20);
},
/**
* Set callable handler for exception handeler or set null to use default.
*/
'exception_handler' => null,
/*'exception_handler' => function($exception) {
header("Status: 404 Not Found");
die('404: ' . $msg);
},*/
/**
* Set callable handler for error page or set null to use default.
*/
'error_page' => null,
/*'error_page' => function($msg) {
header("Status: 404 Not Found");
die('404: ' . $msg);
},*/
);