1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-25 00:45:50 +02:00

Compare commits

...

101 Commits
v0.5 ... v0.6.2

Author SHA1 Message Date
Mikael Roos
8e9a3b68f0 ready for test of remote images #43 2015-01-14 19:33:35 +01:00
Mikael Roos
61afe445f1 ready for test of remote images #43 2015-01-14 19:32:01 +01:00
Mikael Roos
be98ae8979 ready for merge #43 2015-01-14 19:28:52 +01:00
Mikael Roos
f9704a4fbc remote download #43 2015-01-10 20:17:12 +01:00
Mikael Roos
254ddf11f0 pre 0.7 before integrating with remote images 2015-01-08 18:03:15 +01:00
Mikael Roos
d21daa298c pre 0.7 before integrating with remote images
* Adding compare-page for comparing images. Issue #20.
* Added option `no-upscale, nu` as resizing strategy to decline upscaling of smaller images. Fix #61.
* Minor change in `CImage::resize()`, crop now does imagecopy without resamling.
* Correcting internal details for save-as and response json which indicated wrong colors. Fix #62.
* Fixed fill-to-fit that failed when using aspect-ratio. Fix #52.
* JSON returns correct values for resulting image. Fix #58.
* Corrected behaviour for skip-original. Fix #60.
2015-01-08 18:01:48 +01:00
Mikael Roos
cae7a49d21 adding class for remote access 2014-12-23 10:46:00 +01:00
Mikael Roos
f4b3f16443 Adding compare-page for comparing images. 2014-12-19 15:23:21 +01:00
Mikael Roos
b5100845e9 Adding compare-page for comparing images. Issue #20. 2014-12-19 15:21:47 +01:00
Mikael Roos
8c4b22ca66 Prepare to rewrite the resize-method with respect to no-upscale code. 2014-12-15 17:45:21 +01:00
Mikael Roos
d509067759 updating strategies to use for no-upscale, #61 2014-12-15 17:24:49 +01:00
Mikael Roos
5fa05e8282 updating strategies to use for no-upscale 2014-12-15 17:16:41 +01:00
Mikael Roos
1144c8e105 updating strategies to use for no-upscale 2014-12-15 17:14:06 +01:00
Mikael Roos
90bfced741 Added option - no-upscale, nu - as resizing strategy to decline upscaling of smaller images. Fix #61. 2014-12-15 15:41:51 +01:00
Mikael Roos
61e0473f47 CImage::resize now crops using imagecopy without resamling. 2014-12-15 09:41:11 +01:00
Mikael Roos
2dbe33bd8e Correcting internal details for save-as and response json which indicated wrong colors. Fix #62. 2014-12-15 09:24:14 +01:00
Mikael Roos
ece0be086c Correcting internal details for save-as and response json which indicated wrong colors. Fix #62. 2014-12-15 09:19:23 +01:00
Mikael Roos
e236757e5d adding testcases for resizing strategies 2014-12-15 09:18:41 +01:00
Mikael Roos
951231f360 Fixed fill-to-fit that failed when using aspect-ratio. Fix #52. 2014-12-14 17:09:29 +01:00
Mikael Roos
34124e687f Removed &nc 2014-12-14 17:09:12 +01:00
Mikael Roos
ea06d5cfe6 Fixed fill-to-fit that failed when using aspect-ratio. Fix #52. 2014-12-14 17:04:51 +01:00
Mikael Roos
cfc4a5f0ed JSON returns correct values for resulting image. Fix #58. 2014-12-13 00:23:40 +01:00
Mikael Roos
00dca21be0 Corrected behaviour for skip-original. Fix #60 2014-12-13 00:12:39 +01:00
Mikael Roos
9680cd421b spelling 2014-12-06 15:53:14 +01:00
Mikael Roos
b335587aa4 prepare to tag v0.6 2014-12-06 15:39:18 +01:00
Mikael Roos
afa59313e6 prepare to tag v0.6 2014-12-06 15:29:48 +01:00
Mikael Roos
5dddad60eb prepare to tag v0.6 2014-12-06 15:27:16 +01:00
Mikael Roos
af1aa661b9 rewrote docs. tested. prepare to tag v0.6 2014-12-06 14:33:47 +01:00
Mikael Roos
9015e7ce9d Minor cleaning of properties in CImage, fix #23 2014-12-03 16:15:32 +01:00
Mikael Roos
7911a88d6e Adding webroot/htaccess to show off how friendly urls can be created for img.php. 2014-12-03 16:06:16 +01:00
Mikael Roos
2b6952b0ca Adding webroot/htaccess to show off how friendly urls can be created for img.php. Fix #45 2014-12-03 16:04:10 +01:00
Mikael Roos
640e377ea9 Adding webroot/htaccess to show off how friendly urls can be created for img.php. Fix #45 2014-12-03 16:03:46 +01:00
Mikael Roos
cdbc9b4adb correcting issue with PHP 5.3 where array is used as constant 2014-12-03 15:42:49 +01:00
Mikael Roos
3aa5542664 changing comment for bgc. 2014-12-03 15:31:38 +01:00
Mikael Roos
3d352f72fe Merge branch 'master' of github.com:mosbth/cimage 2014-12-03 15:26:38 +01:00
Mikael Roos
f13b602e11 Added option fill-to-fit, ff. Fix #38. 2014-12-03 15:26:17 +01:00
Mikael Roos
f638dd16a7 Added option fill-to-fit, ff. Fix #38. 2014-12-03 15:25:03 +01:00
Mikael Roos
113b62edc0 Added option 'shortcut, sc' to enable configuration of complex expressions. Fix #2. 2014-11-28 16:25:54 +01:00
Mikael Roos
3c04a2dd0f Added support for custom convolutions. Fix #49. 2014-11-27 22:04:41 +01:00
Mikael Roos
832edc9d26 restructured test programs 2014-11-26 15:16:02 +01:00
Mikael Roos
2d09ea4b44 Restructured test-programs. 2014-11-26 15:13:41 +01:00
Mikael Roos
9177d72bea Check if constants exists. Fix #42 2014-11-26 14:45:38 +01:00
Mikael Roos
d4a03b70dd Adding testcase for #40 2014-11-24 10:46:50 +01:00
Mikael Roos
188f8cd64d Adding option taking comma-separated list of 11 float-values, wraps and exposes . #4 2014-11-24 09:27:47 +01:00
Mikael Roos
4dfbcd9784 Changing ppi to dpr. #25 2014-11-24 07:41:32 +01:00
Mikael Roos
35dd5c9064 Adding option which defaults to 1. Set to 2 to get a twice as large image. Useful for Retina displays. Basically a shortcut to enlarge the image. #25 2014-11-21 23:44:19 +01:00
Mikael Roos
1f5f8c02a4 Adding utility to ease gathering stats on cache usage. #21 2014-11-21 23:14:38 +01:00
Mikael Roos
08ee3064d0 * Cache-directory can now be readonly and serve all cached files, still failing when need to save files. #5 2014-11-21 22:31:04 +01:00
Mikael Roos
ba45f746bb * Cache now uses same file extension as original image #37.
* Can output image as json format using `json` #11.
2014-11-21 22:20:30 +01:00
Mikael Roos
ccc59fbb3a Prepare to tag v0.5.3 2014-11-21 21:14:19 +01:00
Mikael Roos
e85bc6cee5 Adding testfiles with capital extension 2014-11-21 21:12:22 +01:00
Mikael Roos
3b7485b3b9 Support filenames of uppercase JPEG, JPG, PNG and GIF, as proposed in #37. 2014-11-21 21:01:22 +01:00
Mikael Roos
c83eac8c3c Changing CImage::output() as proposed in #37. 2014-11-21 20:20:35 +01:00
Mikael Roos
78ac29752e Adding security check that image filename is always below the path
`image_path` as specified in `img_config.php` #37.
2014-11-21 19:57:11 +01:00
Mikael Roos
4b64237a4c Changeing comment 2014-11-21 19:37:33 +01:00
Mikael Roos
85f0e3e7d3 moving testilfes to one dir 2014-11-21 19:35:04 +01:00
Mikael Roos
da227d49dd Use the new config item for checking valid filename characters. 2014-11-21 19:34:01 +01:00
Mikael Roos
26449a3236 Adding configuration item to set what valid characters are for the image
filename.
2014-11-21 19:32:05 +01:00
Mikael Roos
20a4f848b7 Moved all test-files into own directory. 2014-11-21 19:24:36 +01:00
Mikael Roos
ec3a6f3491 check if extension exif is loaded #36 2014-09-01 01:27:45 +02:00
Mikael Roos
8523ef5e31 adding testcases for #36 2014-09-01 00:38:26 +02:00
Mikael Roos
63112f58b1 Cleaning up code #23, added rotate and autoRotate #36 2014-08-31 23:58:02 +02:00
Mikael Roos
c96ed10f80 Cleaning up code #23, added rotate and autoRotate #36 2014-08-31 23:57:34 +02:00
Mikael Roos
67524bd090 Adding MIT license text as should be. 2014-08-21 02:46:00 +02:00
Mikael Roos
1f9a11747b Readding cache dir 2014-08-21 02:37:58 +02:00
Mikael Roos
4ed55d59e3 finally setting jpeg_ignore_warning to true #34 2014-08-21 02:30:32 +02:00
Mikael Roos
8dde82993b improving error handling when opening (non)-recoverable images 2014-08-21 02:23:15 +02:00
Mikael Roos
fb261b1b05 improving error handling when opening (non)-recoverable images 2014-08-21 02:22:20 +02:00
Mikael Roos
1a6cef6580 improving error handling when opening (non)-recoverable images 2014-08-21 02:21:32 +02:00
Mikael Roos
2643d4954f must have @ before open images, warning contra notice, recoverable and non recoverable 2014-08-21 02:13:01 +02:00
Mikael Roos
ef1d56085a Verbose error when failing to open image 2014-08-21 02:08:49 +02:00
Mikael Roos
28cda0ea28 changing error handling to dir when failing to open a corrupt image 2014-08-21 02:02:50 +02:00
Mikael Roos
ed9949b717 adding corrupt jpegs for #34 2014-08-21 01:37:05 +02:00
Mikael Roos
c249a472d6 adding pre 2014-08-21 01:25:19 +02:00
Mikael Roos
c8c2e5f95f updated with change #34 2014-08-21 01:20:50 +02:00
Mikael Roos
8db8501eb0 Setting gd.jpeg_ignore_warning to true #34 as default 2014-08-21 01:19:56 +02:00
Mikael Roos
2b0b3859a7 Extended info printed #35 2014-08-21 00:31:05 +02:00
Mikael Roos
1e70883771 Now sends 404 header as it should #32 when providing a error page 2014-08-20 23:55:23 +02:00
Mikael Roos
b2002d0087 Now sends 404 header as it should #32 when providing a error page 2014-08-20 23:54:13 +02:00
Mikael Roos
9aac0cde8e Removed old description, its in the README now, focus on testcases. 2014-08-20 23:49:25 +02:00
Mikael Roos
3dec1d0a6d Merge pull request #33 from garagesocial/patch-2
Update CImage.php
2014-08-15 08:54:59 +02:00
Garagesocial
577e5fa5d4 Update CImage.php 2014-08-15 02:07:07 -04:00
Mikael Roos
38a6c86317 Merge pull request #31 from garagesocial/patch-1
Comment Typo CImage.php
2014-08-07 08:18:17 +02:00
Garagesocial
dcb390a17b Comment Typo CImage.php 2014-08-06 19:02:55 -04:00
Mikael Roos
9e461787c7 comment reflected wrongly to area variabel, issue #29 2014-05-20 01:39:51 +02:00
Mikael Roos
a96cd7a4cc changed colors 2014-05-20 01:15:53 +02:00
Mikael Roos
98d971204f correcting links to image 2014-05-20 01:04:26 +02:00
Mikael Roos
9707065b9e trying and failing to verify issue 29 2014-05-20 00:56:30 +02:00
Mikael Roos
5cd953b9b3 issue 29 and code formatting 2014-05-20 00:56:08 +02:00
Mikael Roos
b4f51f3438 code formatting and making log() public 2014-05-20 00:55:43 +02:00
Mikael Roos
dedd01bc71 Helper to check if img.php is supported on this system 2014-05-20 00:12:46 +02:00
Mikael Roos
67d0cf27ee code formatting and slightly reformatted verbose output 2014-05-20 00:12:09 +02:00
Mikael Roos
161fdfe769 code formatting 2014-05-20 00:00:27 +02:00
Mikael Roos
6cff9ac105 better error reporting for development environment 2014-05-19 23:59:50 +02:00
Mikael Roos
ec42c41e4d Verified known bug - sharpen acts as blur in PHP 5.5.9 and 5.5.10 #28 2014-04-01 08:56:38 +02:00
Mikael Roos
f12d02b8c1 Correcting issue #27 and removing default config-options from img.php 2014-04-01 08:44:38 +02:00
Mikael Roos
1673cd7aca Correcting issue #26 2014-04-01 08:11:49 +02:00
Mikael Roos
0fee846437 tag v0.5.1 2014-02-12 15:29:58 +01:00
Mikael Roos
c63747a892 Adding empty cache-directory to repo 2014-02-12 15:25:29 +01:00
Mikael Roos
2d8cccc795 Display image in README 2014-02-12 15:22:52 +01:00
Mikael Roos
bb5fd6f115 Display image in README 2014-02-12 15:22:06 +01:00
57 changed files with 3695 additions and 497 deletions

4
.gitignore vendored
View File

@@ -1,4 +1,4 @@
# Cache files #
######################
cache/_*

cache/*

240
CHttpGet.php Normal file
View File

@@ -0,0 +1,240 @@
<?php
/**
* Get a image from a remote server using HTTP GET and If-Modified-Since.
*
*/
class CHttpGet
{
private $request = array();
private $response = array();
/**
* Constructor
*
*/
public function __construct()
{
$this->request['header'] = array();
}
/**
* Set the url for the request.
*
* @param string $url
*
* @return $this
*/
public function setUrl($url)
{
$this->request['url'] = $url;
return $this;
}
/**
* Set custom header field for the request.
*
* @param string $field
* @param string $value
*
* @return $this
*/
public function setHeader($field, $value)
{
$this->request['header'][] = "$field: $value";
return $this;
}
/**
* Set header fields for the request.
*
* @param string $field
* @param string $value
*
* @return $this
*/
public function parseHeader()
{
$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n"));
$output = array();
if ('HTTP' === substr($header[0], 0, 4)) {
list($output['version'], $output['status']) = explode(' ', $header[0]);
unset($header[0]);
}
foreach ($header as $entry) {
$pos = strpos($entry, ':');
$output[trim(substr($entry, 0, $pos))] = trim(substr($entry, $pos + 1));
}
$this->response['header'] = $output;
return $this;
}
/**
* Perform the request.
*
* @param boolean $debug set to true to dump headers.
*
* @return boolean
*/
public function doGet($debug = false)
{
$options = array(
CURLOPT_URL => $this->request['url'],
CURLOPT_HEADER => 1,
CURLOPT_HTTPHEADER => $this->request['header'],
CURLOPT_AUTOREFERER => true,
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => $debug,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 5,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
if (!$response) {
return false;
}
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$this->response['headerRaw'] = substr($response, 0, $headerSize);
$this->response['body'] = substr($response, $headerSize);
$this->parseHeader();
if ($debug) {
$info = curl_getinfo($ch);
echo "Request header<br><pre>", var_dump($info['request_header']), "</pre>";
echo "Response header (raw)<br><pre>", var_dump($this->response['headerRaw']), "</pre>";
echo "Response header (parsed)<br><pre>", var_dump($this->response['header']), "</pre>";
}
curl_close($ch);
return true;
}
/**
* Get HTTP code of response.
*
* @return integer as HTTP status code or null if not available.
*/
public function getStatus()
{
return isset($this->response['header']['status'])
? (int) $this->response['header']['status']
: null;
}
/**
* Get file modification time of response.
*
* @return int as timestamp.
*/
public function getLastModified()
{
return isset($this->response['header']['Last-Modified'])
? strtotime($this->response['header']['Last-Modified'])
: null;
}
/**
* Get content type.
*
* @return string as the content type or null if not existing or invalid.
*/
public function getContentType()
{
$type = isset($this->response['header']['Content-Type'])
? $this->response['header']['Content-Type']
: null;
return preg_match('#[a-z]+/[a-z]+#', $type)
? $type
: null;
}
/**
* Get file modification time of response.
*
* @param mixed $default as default value (int seconds) if date is
* missing in response header.
*
* @return int as timestamp or $default if Date is missing in
* response header.
*/
public function getDate($default = false)
{
return isset($this->response['header']['Date'])
? strtotime($this->response['header']['Date'])
: $default;
}
/**
* Get max age of cachable item.
*
* @param mixed $default as default value if date is missing in response
* header.
*
* @return int as timestamp or false if not available.
*/
public function getMaxAge($default = false)
{
$cacheControl = isset($this->response['header']['Cache-Control'])
? $this->response['header']['Cache-Control']
: null;
$maxAge = null;
if ($cacheControl) {
// max-age=2592000
$part = explode('=', $cacheControl);
$maxAge = ($part[0] == "max-age")
? (int) $part[1]
: null;
}
if ($maxAge) {
return $maxAge;
}
$expire = isset($this->response['header']['Expires'])
? strtotime($this->response['header']['Expires'])
: null;
return $expire ? $expire : $default;
}
/**
* Get body of response.
*
* @return string as body.
*/
public function getBody()
{
return $this->response['body'];
}
}

1540
CImage.php

File diff suppressed because it is too large Load Diff

332
CRemoteImage.php Normal file
View File

@@ -0,0 +1,332 @@
<?php
/**
* Get a image from a remote server using HTTP GET and If-Modified-Since.
*
*/
class CRemoteImage
{
/**
* Path to cache files.
*/
private $saveFolder = null;
/**
* Use cache or not.
*/
private $useCache = true;
/**
* HTTP object to aid in download file.
*/
private $http;
/**
* Status of the HTTP request.
*/
private $status;
/**
* Defalt age for cached items 60*60*24*7.
*/
private $defaultMaxAge = 604800;
/**
* Url of downloaded item.
*/
private $url;
/**
* Base name of cache file for downloaded item.
*/
private $fileName;
/**
* Filename for json-file with details of cached item.
*/
private $fileJson;
/**
* Filename for image-file.
*/
private $fileImage;
/**
* Cache details loaded from file.
*/
private $cache;
/**
* Constructor
*
*/
public function __construct()
{
;
}
/**
* Get status of last HTTP request.
*
* @return int as status
*/
public function getStatus()
{
return $this->status;
}
/**
* Get JSON details for cache item.
*
* @return array with json details on cache.
*/
public function getDetails()
{
return $this->cache;
}
/**
* Set the path to the cache directory.
*
* @param boolean $use true to use the cache and false to ignore cache.
*
* @return $this
*/
public function setCache($path)
{
$this->saveFolder = $path;
return $this;
}
/**
* Decide if the cache should be used or not before trying to download
* a remote file.
*
* @param boolean $use true to use the cache and false to ignore cache.
*
* @return $this
*/
public function useCache($use = true)
{
$this->useCache = $use;
return $this;
}
/**
* Translate a content type to a file extension.
*
* @param string $type a valid content type.
*
* @return string as file extension or false if no match.
*/
function contentTypeToFileExtension($type) {
$extension = array(
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
);
return isset($extension[$type])
? $extension[$type]
: false;
}
/**
* Set header fields.
*
* @return $this
*/
function setHeaderFields() {
$this->http->setHeader("User-Agent", "CImage/0.6 (PHP/". phpversion() . " cURL)");
$this->http->setHeader("Accept", "image/jpeg,image/png,image/gif");
if ($this->useCache) {
$this->http->setHeader("Cache-Control", "max-age=0");
} else {
$this->http->setHeader("Cache-Control", "no-cache");
$this->http->setHeader("Pragma", "no-cache");
}
}
/**
* Save downloaded resource to cache.
*
* @return string as path to saved file or false if not saved.
*/
function save() {
$this->cache = array();
$date = $this->http->getDate(time());
$maxAge = $this->http->getMaxAge($this->defaultMaxAge);
$lastModified = $this->http->getLastModified();
$type = $this->http->getContentType();
$extension = $this->contentTypeToFileExtension($type);
$this->cache['Date'] = gmdate("D, d M Y H:i:s T", $date);
$this->cache['Max-Age'] = $maxAge;
$this->cache['Content-Type'] = $type;
$this->cache['File-Extension'] = $extension;
if ($lastModified) {
$this->cache['Last-Modified'] = gmdate("D, d M Y H:i:s T", $lastModified);
}
if ($extension) {
$this->fileImage = $this->fileName . "." . $extension;
// Save only if body is a valid image
$body = $this->http->getBody();
$img = imagecreatefromstring($body);
if ($img !== false) {
file_put_contents($this->fileImage, $body);
file_put_contents($this->fileJson, json_encode($this->cache));
return $this->fileImage;
}
}
return false;
}
/**
* Got a 304 and updates cache with new age.
*
* @return string as path to cached file.
*/
function updateCacheDetails() {
$date = $this->http->getDate(time());
$maxAge = $this->http->getMaxAge($this->defaultMaxAge);
$lastModified = $this->http->getLastModified();
$this->cache['Date'] = gmdate("D, d M Y H:i:s T", $date);
$this->cache['Max-Age'] = $maxAge;
if ($lastModified) {
$this->cache['Last-Modified'] = gmdate("D, d M Y H:i:s T", $lastModified);
}
file_put_contents($this->fileJson, json_encode($this->cache));
return $this->fileImage;
}
/**
* Download a remote file and keep a cache of downloaded files.
*
* @param string $url a remote url.
*
* @return string as path to downloaded file or false if failed.
*/
function download($url) {
$this->http = new CHttpGet();
$this->url = $url;
// First check if the cache is valid and can be used
$this->loadCacheDetails();
if ($this->useCache) {
$src = $this->getCachedSource();
if ($src) {
$this->status = 1;
return $src;
}
}
// Do a HTTP request to download item
$this->setHeaderFields();
$this->http->setUrl($this->url);
$this->http->doGet();
$this->status = $this->http->getStatus();
if ($this->status === 200) {
return $this->save();
} else if ($this->status === 304) {
return $this->updateCacheDetails();
}
return false;
}
/**
* Get the path to the cached image file if the cache is valid.
*
* @return $this
*/
public function loadCacheDetails()
{
$cacheFile = str_replace(["/", ":", "#", ".", "?"], "-", $this->url);
$this->fileName = $this->saveFolder . $cacheFile;
$this->fileJson = $this->fileName . ".json";
if (is_readable($this->fileJson)) {
$this->cache = json_decode(file_get_contents($this->fileJson), true);
}
}
/**
* Get the path to the cached image file if the cache is valid.
*
* @return string as the path ot the image file or false if no cache.
*/
public function getCachedSource()
{
$this->fileImage = $this->fileName . "." . $this->cache['File-Extension'];
$imageExists = is_readable($this->fileImage);
// Is cache valid?
$date = strtotime($this->cache['Date']);
$maxAge = $this->cache['Max-Age'];
$now = time();
if ($imageExists && $date + $maxAge > $now) {
return $this->fileImage;
}
// Prepare for a 304 if available
if ($imageExists && isset($this->cache['Last-Modified'])) {
$this->http->setHeader("If-Modified-Since", $this->cache['Last-Modified']);
}
return false;
}
}

View File

@@ -1,2 +1,21 @@
This is a software solution to a general known problem.
Free software. Use at own risk.
The MIT License (MIT)
Copyright (c) 2012 - 2014 Mikael Roos, me@mikaelroos.se
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

324
README.md
View File

@@ -4,34 +4,57 @@ Image conversion on the fly using PHP
About
-------------------------------------
`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.
`CImage` is a PHP class enabling 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 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.
Server-side image processing is a most useful tool for any web developer, `img.php` has an easy to use interface and its powerful when you integrate it with your website. Using it might decrease the time and effort put in managing images and improve your workflow when creating content for websites.
Read more on http://dbwebb.se/opensource/cimage
Enjoy!
Mikael Roos (me@mikaelroos.se)
This software is free and open source, licensed according MIT.
License
-------------------------------------
Use case
--------------------------------------
This is free software and open source software, licensed according MIT.
You got an image from your friend who took it with the iPhone and you want to put it up on your website.
<img src="http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=issue36/me-270.jpg&w=300" alt="">
The original image is looking like this one, scaled down to a width of 300 pixels.
So, you need to rotate it and crop off some parts to make it intresting.
To show it off, I'll autorotate the image based on its EXIF-information, I will crop it to a thumbnail of 100x100 pixels and add a filter to make it greyscale finishing up with a sharpen effect. Just for the show I'll rotate the image 25 degrees - do not ask me why.
Lets call this *the URL-Photoshopper*. This is how the magic looks like.
`img.php?src=issue36/me-270.jpg&w=100&h=100&cf&aro&rb=-25&a=8,30,30,38&f=grayscale`<br>`&convolve=sharpen-alt`
<img src="http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=issue36/me-270.jpg&w=100&h=100&cf&aro&rb=-25&a=8,30,30,38&f=grayscale&convolve=sharpen-alt" alt="">
For myself, I use `img.php` to put up all images on my website, it gives me the power of affecting the resulting images - without opening up a photo-editing application.
Installation and get going
-------------------------------------
Requirements
--------------------------------------
**Latest stable version is v0.5 released 2014-02-12.**
`CImage` and `img.php` supports GIF (with transparency), JPEG and PNG (8bit transparent, 24bit semi transparent) images. It requires PHP 5.3 and PHP GD. You optionally need the EXIF extension to support auto-rotation of JPEG-images.
Installation
--------------------------------------
The [sourcode is available on GitHub](https://github.com/mosbth/cimage). Clone, fork or [download as zip](https://github.com/mosbth/cimage/archive/master.zip).
I prefer cloning like this. Do switch to the latest stable version.
**Latest stable version is v0.6.1 released 2015-01-08.**
```bash
git clone git://github.com/mosbth/cimage.git
cd cimage
git checkout v0.5
git checkout v0.6.1
```
Make the cache-directory writable by the webserver.
@@ -40,63 +63,189 @@ Make the cache-directory writable by the webserver.
chmod 777 cache
```
Try it out by pointing your browser to the test file `webroot/test.php`.
Get going quickly
--------------------------------------
###Check out the test page
Try it out by pointing your browser to the test file `webroot/test/test.php`. It will show some images and you can review how they are created.
###Process your first image
<img src="http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim04.png&amp;w=w2&amp;a=40,0,50,0" alt=''>
Try it yourself by opening up an image in your browser. Start with `webroot/img.php?src=kodim04.png` and then try to resize it to a thumbnail `webroot/img.php?src=kodim04.png&width=100&height=100&crop-to-fit`.
###What does "processing the image" involves?
Add `&verbose` to the link to get a verbose output of what is happens during image processing. This is useful for developers or those who seek a deeper understanding on how it all works.
###Check your system
Open up `webroot/check_system.php` if you need to troubleshoot or if you are uncertain if your system has the right extensions loaded.
###How does it work?
Review the settings in `webroot/img_config.php` and check out `webroot/img.php` on how it uses `CImage`.
The programatic flow, just to get you oriented in the environment, is.
1. Start in `img.php`.
2. `img.php` reads configuration details from `img_config.php`.
3. `img.php` reads and processes incoming `$_GET` arguments to prepare using `CImage`.
4. `img.php` uses `CImage`.
5. `CImage` processes and outputs the image according to how its used.
Read on to learn more on how to use `img.php`.
Usage
-------------------------------------
Basic 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.
###Select the source
Open an image through `img.php` by using its `src` attribute.
> `img.php?src=kodim13.png`
It looks like this.
<img src=http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim13.png&w=w1&save-as=jpg alt="">
All images are stored in a directory structure and you access them as `?src=dir1/dir2/image.png`.
###Resize using constraints on width and height
Create a thumbnail of the image by applying constraints on width and height, or one of them.
| `&width=150` | `&height=150` | `&w=150&h=150` |
|---------------------|---------------------|---------------------|
| <img src=http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim13.png&w=150 alt=''> | <img src=http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim13.png&h=150 alt=''> | <img src=http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim13.png&w=150&h=150 alt=''> |
By setting width, height or both, the image gets resized to be *not larger* than the defined dimensions *and* keeping its original aspect ratio.
Think of the constraints as a imaginary box where the image should fit. With `width=150` and `height=150` the box would have the dimension of 150x150px. A landscape image would fit in that box and its width would be 150px and its height depending on the aspect ratio, but for sure less than 150px. A portrait image would fit with a height of 150px and the width depending on the aspect ratio, but surely less than 150px.
###Resize to fit a certain dimension
Creating a thumbnail with a certain dimension of width and height, usually involves stretching or cropping the image to fit in the selected dimensions. Here is how you create a image that has the exact dimensions of 300x150 pixels, by either *stretching*, *cropping* or *fill to fit*.
| What | The image |
|---------------------|---------------------|
| **Original.** The original image resized with a max width and max height.<br>`?w=300&h=150` | <img src=http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim13.png&w=300&h=150 alt=''> |
| **Stretch.** Stretch the image so that the resulting image has the defined width and height.<br>`?w=300&h=150&stretch` | <img src=http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim13.png&w=300&h=150&stretch alt=''> |
| **Crop to fit.** Keep the aspect ratio and crop out the parts of the image that does not fit.<br>`?w=300&h=150&crop-to-fit` | <img src=http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim13.png&w=300&h=150&crop-to-fit alt=''> |
| **Fill to fit.** Keep the aspect ratio and fill then blank space with a background color.<br>`?w=300&h=150&fill-to-fit=006600` | <img src=http://dbwebb.se/kod-exempel/cimage/webroot/img.php?src=kodim13.png&w=300&h=150&fill-to-fit=006600 alt=''> |
Learn to crop your images, creative cropping can make wonderful images from appearingly useless originals.
Stretching might work, like in the above example where you can not really notice that the image is stretched. But usually, stretching is not that a good option since it distorts the ratio resulting in a image with incorrect dimensions. Stretching a face may not turn out particularly well.
Fill to fit is useful when you have some image that must fit in a certain dimension and stretching nor cropping can do it. Carefully choose the background color to make a good resulting image. Choose the same background color as your website and no one will notice.
###List of parameters
`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=''> |
| <img src=http://dbwebb.se/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.
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.
Option `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 |
| Parameter | Explained |
|----------------|----------------------------------------------|
| `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. |
| `json` | Output a JSON-representation of the image, useful for testing or optimizing when one wants to know the image dimensions, before using it. |
####Options for resizing image
####Options for deciding width and height of target 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.
These options are all affecting the final dimensions, width and height, of the resulting image.
| Parameter | Explained |
| 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. |
| `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 for portrait images, compared to landscape images. |
| `dpr, device-pixel-ratio` | Default value is 1, set to 2 when you are delivering the image to a high density screen, `dpr=2` or `dpr=1.4`. Its a easy way to say the image should have larger dimensions. The resulting image will be twice as large (or 1.4 times), keeping its aspect ratio. |
####Options for resize strategy
These options affect strategy to use when resizing an image into a target image that has both width and height set.
| Parameter | Explained |
|----------------|----------------------------------------------|
| `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 of using `crop`. |
| `cf, crop-to-fit` | Set together with both `h` and `w` to make the image fit into dimensions, and crop out the rest of the image. |
| `ff, fill-to-fit` | Set together with both `h` and `w` to make the image fit into dimensions, and fill the rest using a background color. You can optionally supply a background color as this `ff=00ff00`, or `ff=00ff007f` when using the alpha channel. |
| `nu, no-upscale` | Avoid smaller images from being upscaled to larger ones. Combine with `stretch`, `crop-to-fit` or `fill-to-fit` to get the smaller image centered on a larger canvas. The requested dimension for the target image are thereby met. |
####Options for cropping part of image
These options enable to decide what part of image to crop out.
| Parameter | Explained |
|----------------|----------------------------------------------|
| `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 the 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. |
####General processing options
These options are general options affecting processing.
| Parameter | Explained |
|----------------|----------------------------------------------|
| `bgc, bg-color` | Set the backgroundcolor to use (if its needed). Use six hex digits as `bgc=00ff00` and 8 digits when using the alpha channel, as this `bgc=00ff007f`. The alpha value can be between 00 and 7f. |
####Processing of image before resizing
These options are executed *before* the image is resized.
This option are executed *before* the image is resized.
| Parameter | Explained |
| 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. |
| `rb, rotate-before` | Rotate the image before its processed, send the angle as parameter `rb=45`. |
| `aro, auto-rotate` | Auto rotate the image based on EXIF information (useful when using images from smartphones). |
@@ -104,34 +253,105 @@ These options are executed *before* the image is resized.
These options are executed *after* the image is resized.
| Parameter | Explained |
| 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). |
| `ra, rotate-after`<br>`r, rotate` | Rotate the image after its processed, send the angle as parameter `ra=45`. |
| `sharpen` | Appy a convolution filter that sharpens the image. |
| `emboss` | Appy a convolution filter with an emboss effect. |
| `blur` | Appy a convolution filter with a blur effect. |
| `convolve` | Appy custom convolution filter as a 3x3 matrix, a divisor and offset, `convolve=0,-1,0,-1,5,-1,0,-1,0,1,0` sharpens the image. |
| `convolve` | Use predefined convolution expression as `convolve=sharpen-alt` or a serie of convolutions as `convolve=draw,mean,motion`. These are supported out of the box: `lighten`, `darken`, `sharpen`, `sharpen-alt`, `emboss`, `emboss-alt`, `blur`, `gblur`, `edge`, `edge-alt`, `draw`, `mean`, `motion`. Add your own, or overwrite existing, in `img_config.php`. |
| `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`. |
| `sc, shortcut` | Save longer expressions in `img_config.php`. One place to change your favorite processing options, use as `sc=sepia` which is a shortcut for `&f=grayscale&f0=brightness,-10&f1=contrast,-20&f2=colorize,120,60,0,0&sharpen`. |
####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`. |
Documentation
--------------------------------------
Read full documentation at:
http://dbwebb.se/opensource/cimage
Revision history
-------------------------------------
v0.6.2 (2015-01-14)
* Added support for download of remote images #43.
v0.5 (2014-02-07)
v0.6.1 (2015-01-08)
* Adding compare-page for comparing images. Issue #20.
* Added option `no-upscale, nu` as resizing strategy to decline upscaling of smaller images. Fix #61.
* Minor change in `CImage::resize()`, crop now does imagecopy without resamling.
* Correcting internal details for save-as and response json which indicated wrong colors. Fix #62.
* Fixed fill-to-fit that failed when using aspect-ratio. Fix #52.
* JSON returns correct values for resulting image. Fix #58.
* Corrected behaviour for skip-original. Fix #60.
v0.6 (2014-12-06)
* Rewrote and added documentation.
* Moved conolution expressesion from `img_config.php` to `CImage`.
* Minor cleaning of properties in `CImage`. Fix #23.
* Adding `webroot/htaccess` to show off how friendly urls can be created for `img.php`. Fix #45.
* Added option `fill-to-fit, ff`. Fix #38.
* Added option `shortcut, sc` to enable configuration of complex expressions. Fix #2.
* Added support for custom convolutions. Fix #49.
* Restructured testprograms. Fix #41.
* Corrected json on PHP 5.3. Fix #42.
* Improving template for tests in `webroot/tests` when testing out #40.
* Adding testcase for #40.
* Adding option `convolve` taking comma-separated list of 11 float-values, wraps and exposes `imageconvoluttion()`. #4
* Adding option `dpr, device-pixel-ratio` which defaults to 1. Set to 2 to get a twice as large image. Useful for Retina displays. Basically a shortcut to enlarge the image.
* Adding utility `cache.bash` to ease gathering stats on cache usage. #21
* Cache-directory can now be readonly and serve all cached files, still failing when need to save files. #5
* Cache now uses same file extension as original image #37.
* Can output image as json format using `json` #11.
v0.5.3 (2014-11-21)
* Support filenames of uppercase JPEG, JPG, PNG and GIF, as proposed in #37.
* Changing `CImage::output()` as proposed in #37.
* Adding security check that image filename is always below the path `image_path` as specified in `img_config.php` #37.
* Adding configuration item in `img_config.php` for setting valid characters in image filename.
* Moving `webroot/test*` into directory `webroot/test`.
* `webroot/check_system.php` now outputs if extension for exif is loaded.
* Broke API when `initDimensions()` split into two methods, new `initDimensions()` and `loadImageDetails()`.
* Added `autoRotate, aro` to auto rotate image based on EXIF information.
* Added `bgColor, bgc` to use as backgroundcolor when needing a filler color, for example rotate 45.
* Added `rotateBefore, rb` to rotate image a certain angle before processing.
* Added `rotateAfter, ra` to rotate image a certain angle after processing.
* Cleaned up code formatting, removed trailing spaces.
* Removed @ from opening images, better to display correct warning when failing #34, but put it back again.
* Setting gd.jpeg_ignore_warning to true as default #34.
* `webroot/check_system.php` now outputs version of PHP and GD.
* #32 correctly send 404 header when serving an error message.
* Trying to verify issue #29, but can not.
* Adding structure for testprograms together with, use `webroot/test_issue29.php` as sample.
* Improving code formatting.
* Moving parts of verbose output from img.php to CImage.php.
v0.5.2 (2014-04-01)
* Correcting issue #26 providing error message when not using postprocessing.
* Correcting issue #27 warning of default timezone.
* Removed default $config options in `img.php`, was not used, all configuration should be in `img_config.php`.
* Verified known bug - sharpen acts as blur in PHP 5.5.9 and 5.5.10 #28
v0.5.1 (2014-02-12)
* Display image in README-file.
* Create an empty `cache` directory as part of repo.
v0.5 (2014-02-12)
* Change constant name `CImage::PNG_QUALITY_DEFAULT` to `CImage::PNG_COMPRESSION_DEFAULT`.
* Split JPEG quality and PNG compression, `CImage->quality` and `CImage->compression`
@@ -154,7 +374,7 @@ v0.4.1 (2014-01-27)
* Fixed crop whole image by setting crop=0,0,0,0
* Use negative values for crop width & height to base calulation on original width/height and withdraw selected amount.
* Correcting jpeg when setting quality.
* Removed obsolete reference to `$newName` in `CImage::__construct()` (issue 1).
* Removed obsolete reference to `$newName` in `CImage::__construct()` (issue 1).
v0.4 (2013-10-08)
@@ -186,8 +406,8 @@ image.
* Predefined sizes can be configured for width in `img.php`.
* Corrected to make crop work with width or height in combination with crop-to-fit.
v0.2 (2012-05-09)
v0.2 (2012-05-09)
* Implemented filters as in http://php.net/manual/en/function.imagefilter.php
* Changed `crop` to `crop_to_fit`, works the same way.
@@ -196,16 +416,16 @@ v0.2 (2012-05-09)
* Added testcases for above.
v0.1.1 (2012-04-27)
v0.1.1 (2012-04-27)
* Corrected calculation where both width and height were set.
v0.1 (2012-04-25)
v0.1 (2012-04-25)
* Initial release after rewriting some older code doing the same, but not that good and flexible.
<pre>
.
.
..: Copyright 2012-2014 by Mikael Roos (me@mikaelroos.se)
</pre>

23
autoload.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
/**
* Autoloader for CImage and related class files.
*
*/
//include __DIR__ . "/../CHttpGet.php";
//include __DIR__ . "/../CRemoteImage.php";
//include __DIR__ . "/../CImage.php";
/**
* Autoloader for classes.
*
* @param string $class the fully-qualified class name.
*
* @return void
*/
spl_autoload_register(function ($class) {
//$path = CIMAGE_SOURCE_PATH . "/{$class}.php";
$path = __DIR__ . "/{$class}.php";
if(is_file($path)) {
require($path);
}
});

36
cache.bash Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
#
# Specify the utilities used
#
ECHO="printf"
#
# Main, start by checking basic usage
#
if [ $# -lt 1 ]
then
$ECHO "Usage: $0 [cache-dir]\n"
exit 1
elif [ ! -d "$1" ]; then
$ECHO "Usage: $0 [cache-dir]\n"
$ECHO "$1 is not a directory.\n"
exit 1
fi
#
# Print out details on cache-directory
#
$ECHO "Total size: $( du -sh $1 | cut -f1 )"
$ECHO "\nNumber of files: $( find $1 | wc -l )"
$ECHO "\n\nTop-5 largest files:\n"
$ECHO "$( du -s $1/* | sort -nr | head -5 )"
$ECHO "\n\nLast-5 created files:\n"
$ECHO "$( find $1/* -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r | head -5 )"
$ECHO "\n\nLast-5 accessed files:\n"
$ECHO "$( find $1/* -printf '%AY-%Am-%Ad %AH:%AM %f\n' | sort -r | head -5 )"
$ECHO "\n"

1
cache/README.md vendored Normal file
View File

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

15
webroot/check_system.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
echo 'Current PHP version: ' . phpversion() . '<br><br>';
echo 'Running on: ' . $_SERVER['SERVER_SOFTWARE'] . '<br><br>';
$no = extension_loaded('gd') ? null : 'NOT';
echo "Extension gd is $no loaded.<br>";
$no = extension_loaded('exif') ? null : 'NOT';
echo "Extension exif is $no loaded.<br>";
if (!$no) {
echo "<pre>", var_dump(gd_info()), "</pre>";
}

View File

@@ -0,0 +1,13 @@
<?php
$script = <<<EOD
CImage.compare({
"input1": "../img.php?src=car.png",
"input2": "../img.php?src=car.png&sharpen",
"input3": "../img.php?src=car.png&blur",
"input4": "../img.php?src=car.png&emboss",
"json": true,
"stack": false
});
EOD;
include __DIR__ . "/compare.php";

106
webroot/compare/compare.php Normal file
View File

@@ -0,0 +1,106 @@
<!doctype html>
<html lang=en>
<head>
<style>
body {
}
input[type=text] {
width: 400px;
}
.hidden {
display: none;
}
#wrap {
position: relative;
overflow: visible;
}
.stack {
position: absolute;
left: 0;
top: 0;
}
.area {
float: left;
padding: 1em;
background-color: #fff;
}
.top {
z-index: 10;
}
</style>
</head>
<body>
<h1>Compare images</h1>
<p>Add link to images and visually compare them. Change the link och press return to load the image. <a href="http://dbwebb.se/opensource/cimage">Read more...</a></p>
<form>
<p>
<label>Image 1: <input type="text" id="input1" data-id="1"></label> <img id="thumb1"></br>
<label>Image 2: <input type="text" id="input2" data-id="2"></label> <img id="thumb2"></br>
<label>Image 3: <input type="text" id="input3" data-id="3"></label> <img id="thumb3"></br>
<label>Image 4: <input type="text" id="input4" data-id="4"></label> <img id="thumb4"></br>
<label><input type="checkbox" id="viewDetails">Hide image details?</label><br/>
<label><input type="checkbox" id="stack">Stack images?</label>
</p>
</form>
<div id="buttonWrap" class="hidden">
<button id="button1" class="button" data-id="1">Image 1</button>
<button id="button2" class="button" data-id="2">Image 2</button>
<button id="button3" class="button" data-id="3">Image 3</button>
<button id="button4" class="button" data-id="4">Image 4</button>
</div>
<div id="wrap">
<div id="area1" class="area">
<code>Image 1</code><br>
<img id="img1">
<pre id="json1" class="json"></pre>
</div>
<div id="area2" class="area">
<code>Image 2</code><br>
<img id="img2">
<pre id="json2" class="json"></pre>
</div>
<div id="area3" class="area">
<code>Image 3</code><br>
<img id="img3">
<pre id="json3" class="json"></pre>
</div>
<div id="area4" class="area">
<code>Image 4</code><br>
<img id="img4">
<pre id="json4" class="json"></pre>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="../js/cimage.js"></script>
<script>
<?php
if (isset($script)) {
echo $script;
} else {
echo "CImage.compare({});";
} ?>
</script>
</html>

17
webroot/htaccess Normal file
View File

@@ -0,0 +1,17 @@
#
# Rewrite to have friendly urls to img.php, edit it to suite your environment.
#
# The example is set up as following.
#
# img A directory where all images are stored
# img/me.jpg Access a image as usually.
# img/img.php This is where I choose to place img.php (and img_config.php).
# image/me.jpg Access a image though img.php using htaccess rewrite.
# image/me.jpg?w=300 Using options to img.php.
#
# Subdirectories also work.
# img/me/me.jpg Direct access to the image.
# image/me/me.jpg Accessed through img.php.
# image/me/me.jpg?w=300 Using options to img.php.
#
RewriteRule ^image/(.*)$ img/img.php?src=$1 [QSA,NC,L]

View File

@@ -5,6 +5,7 @@
*/
/**
* Default configuration options, can be overridden in own config-file.
*
@@ -12,9 +13,9 @@
*
* @return void
*/
function errorPage($msg)
function errorPage($msg)
{
header("Status: 404 Not Found");
header("HTTP/1.0 404 Not Found");
die('img.php say 404: ' . $msg);
}
@@ -23,7 +24,7 @@ function errorPage($msg)
/**
* Custom exception handler.
*/
set_exception_handler(function($exception) {
set_exception_handler(function ($exception) {
errorPage("<p><b>img.php: Uncaught exception:</b> <p>" . $exception->getMessage() . "</p><pre>" . $exception->getTraceAsString(), "</pre>");
});
@@ -37,7 +38,7 @@ set_exception_handler(function($exception) {
*
* @return mixed value from $_GET or default value.
*/
function get($key, $default = null)
function get($key, $default = null)
{
if (is_array($key)) {
foreach ($key as $val) {
@@ -62,9 +63,27 @@ function get($key, $default = null)
*
* @return mixed value as $defined or $undefined.
*/
function getDefined($key, $defined, $undefined)
function getDefined($key, $defined, $undefined)
{
return get($key) === null ? $undefined : $defined;
return get($key) === null ? $undefined : $defined;
}
/**
* Get value from config array or default if key is not set in config array.
*
* @param string $key the key in the config array.
* @param mixed $default value to be default if $key is not set in config.
*
* @return mixed value as $config[$key] or $default.
*/
function getConfig($key, $default)
{
global $config;
return isset($config[$key])
? $config[$key]
: $default;
}
@@ -76,7 +95,7 @@ function getDefined($key, $defined, $undefined)
*
* @return void or array.
*/
function verbose($msg = null)
function verbose($msg = null)
{
global $verbose;
static $log = array();
@@ -95,19 +114,26 @@ function verbose($msg = null)
/**
* Default configuration options, can be overridden in own config-file.
* Get configuration options from file.
*/
$config = array(
);
$configFile = __DIR__.'/'.basename(__FILE__, '.php').'_config.php';
$config = array_merge($config, require $configFile);
$config = require $configFile;
call_user_func($config['error_reporting']);
/**
* Set default timezone if not set or if its set in the config-file.
*/
if (isset($config['default_timezone'])) {
date_default_timezone_set($config['default_timezone']);
} else if (!ini_get('default_timezone')) {
date_default_timezone_set('UTC');
}
/**
* verbose, v - do a verbose dump of what happens
*/
@@ -115,15 +141,109 @@ $verbose = getDefined(array('verbose', 'v'), true, false);
/**
* Get the source files.
*/
$autoloader = getConfig('autoloader', false);
$cimageClass = getConfig('cimage_class', false);
if ($autoloader) {
require $autoloader;
} else if ($cimageClass) {
require $cimageClass;
}
/**
* Create the class for the image.
*/
$img = new CImage();
$img->setVerbose($verbose);
/**
* Allow or disallow remote download of images from other servers.
*
*/
$allowRemote = getConfig('remote_allow', false);
$remotePwd = getConfig('remote_password', false);
$pwd = get(array('password', 'pwd'), null);
// Check if passwords match, if configured to use passwords
$passwordMatch = null;
if ($remotePwd != false) {
if ($remotePwd == $pwd) {
$passwordMatch = true;
} else {
$passwordMatch = false;
errorPage('Trying to download remote image but missing password.');
}
}
if ($allowRemote && $passwordMatch !== false) {
$pattern = getConfig('remote_pattern', null);
$img->setRemoteDownload($allowRemote, $pattern);
}
/**
* shortcut, sc - extend arguments with a constant value, defined
* in config-file.
*/
$shortcut = get(array('shortcut', 'sc'), null);
verbose("shortcut = $shortcut");
if (isset($shortcut)
&& isset($config['shortcut'])
&& isset($config['shortcut'][$shortcut])) {
parse_str($config['shortcut'][$shortcut], $get);
verbose("shortcut-constant = {$config['shortcut'][$shortcut]}");
$_GET = array_merge($_GET, $get);
}
/**
* src - the source image file.
*/
$srcImage = get('src')
or errorPage('Must set src-attribute.');
preg_match('#^[a-z0-9A-Z-/_\.]+$#', $srcImage)
// Check for valid/invalid characters
preg_match($config['valid_filename'], $srcImage)
or errorPage('Filename contains invalid characters.');
if ($allowRemote && $img->isRemoteSource($srcImage)) {
// If source is a remote file, ignore local file checks.
} else if ($config['image_path_constraint']) {
// Check that the image is a file below the directory 'image_path'.
$pathToImage = realpath($config['image_path'] . $srcImage);
$imageDir = realpath($config['image_path']);
is_file($pathToImage)
or errorPage(
'Source image is not a valid file, check the filename and that a
matching file exists on the filesystem.'
);
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
or errorPage(
'Security constraint: Source image is not below the directory "image_path"
as specified in the config file img_config.php.'
);
}
verbose("src = $srcImage");
@@ -141,12 +261,12 @@ if (isset($sizes[$newWidth])) {
// Support width as % of original width
if ($newWidth[strlen($newWidth)-1] == '%') {
is_numeric(substr($newWidth, 0, -1))
or errorPage('Width % not numeric.');
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.');
is_null($newWidth)
or ($newWidth > 10 && $newWidth <= $config['max_width'])
or errorPage('Width out of range.');
}
verbose("new width = $newWidth");
@@ -165,11 +285,11 @@ if (isset($sizes[$newHeight])) {
// height
if ($newHeight[strlen($newHeight)-1] == '%') {
is_numeric(substr($newHeight, 0, -1))
or errorPage('Height % out of range.');
is_numeric(substr($newHeight, 0, -1))
or errorPage('Height % out of range.');
} else {
is_null($newHeight)
or ($newHeight > 10 && $newHeight <= $config['max_height'])
is_null($newHeight)
or ($newHeight > 10 && $newHeight <= $config['max_height'])
or errorPage('Hight out of range.');
}
@@ -195,8 +315,8 @@ if ($negateAspectRatio) {
$aspectRatio = 1 / $aspectRatio;
}
is_null($aspectRatio)
or is_numeric($aspectRatio)
is_null($aspectRatio)
or is_numeric($aspectRatio)
or errorPage('Aspect ratio out of range');
verbose("aspect ratio = $aspectRatio");
@@ -212,6 +332,45 @@ verbose("crop to fit = $cropToFit");
/**
* Set default background color from config file.
*/
if (isset($config['background_color'])) {
$img->setDefaultBackgroundColor($config['background_color']);
verbose("Using default background_color = {$config['background_color']}");
}
/**
* bgColor - Default background color to use
*/
$bgColor = get(array('bgColor', 'bg-color', 'bgc'), null);
verbose("bgColor = $bgColor");
/**
* fill-to-fit, ff - affecting the resulting image width, height and resize options
*/
$fillToFit = get(array('fill-to-fit', 'ff'), null);
verbose("fill-to-fit = $fillToFit");
if ($fillToFit !== null) {
if (!empty($fillToFit)) {
$bgColor = $fillToFit;
verbose("fillToFit changed bgColor to = $bgColor");
}
$fillToFit = true;
verbose("fill-to-fit (fixed) = $fillToFit");
}
/**
* no-ratio, nr, stretch - affecting the resulting image width, height and resize options
*/
@@ -242,7 +401,7 @@ verbose("area = $area");
/**
* skip-original, so - skip the original image and always process a new image
*/
$useOriginal = getDefined(array('save-as', 'sa'), false, true);
$useOriginal = getDefined(array('skip-original', 'so'), false, true);
verbose("use original = $useOriginal");
@@ -262,8 +421,8 @@ verbose("use cache = $useCache");
*/
$quality = get(array('quality', 'q'));
is_null($quality)
or ($quality > 0 and $quality <= 100)
is_null($quality)
or ($quality > 0 and $quality <= 100)
or errorPage('Quality out of range');
verbose("quality = $quality");
@@ -275,9 +434,9 @@ verbose("quality = $quality");
*/
$compress = get(array('compress', 'co'));
is_null($compress)
or ($compress > 0 and $compress <= 9)
is_null($compress)
or ($compress > 0 and $compress <= 9)
or errorPage('Compress out of range');
verbose("compress = $compress");
@@ -298,8 +457,8 @@ verbose("save as = $saveAs");
*/
$scale = get(array('scale', 's'));
is_null($scale)
or ($scale >= 0 and $quality <= 400)
is_null($scale)
or ($scale >= 0 and $scale <= 400)
or errorPage('Scale out of range');
verbose("scale = $scale");
@@ -342,19 +501,54 @@ verbose("blur = $blur");
/**
* rotateBefore - Rotate the image with an angle, before processing
*/
$rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb'));
is_null($rotateBefore)
or ($rotateBefore >= -360 and $rotateBefore <= 360)
or errorPage('RotateBefore out of range');
verbose("rotateBefore = $rotateBefore");
/**
* rotateAfter - Rotate the image with an angle, before processing
*/
$rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r'));
is_null($rotateAfter)
or ($rotateAfter >= -360 and $rotateAfter <= 360)
or errorPage('RotateBefore out of range');
verbose("rotateAfter = $rotateAfter");
/**
* autoRotate - Auto rotate based on EXIF information
*/
$autoRotate = getDefined(array('autoRotate', 'auto-rotate', 'aro'), true, false);
verbose("autoRotate = $autoRotate");
/**
* filter, f, f0-f9 - Processing option, post filter for various effects using imagefilter()
*/
$filters = array();
$filter = get(array('filter', 'f'));
if ($filter) {
$filters[] = $filter;
if ($filter) {
$filters[] = $filter;
}
for ($i = 0; $i < 10; $i++) {
$filter = get(array("filter{$i}", "f{$i}"));
if ($filter) {
$filters[] = $filter;
if ($filter) {
$filters[] = $filter;
}
}
@@ -362,6 +556,48 @@ verbose("filters = " . print_r($filters, 1));
/**
* json - output the image as a JSON object with details on the image.
*/
$outputFormat = getDefined('json', 'json', null);
verbose("json = $outputFormat");
/**
* dpr - change to get larger image to easier support larger dpr, such as retina.
*/
$dpr = get(array('ppi', 'dpr', 'device-pixel-ratio'), 1);
verbose("dpr = $dpr");
/**
* convolve - image convolution as in http://php.net/manual/en/function.imageconvolution.php
*/
$convolve = get('convolve', null);
// Check if the convolve is matching an existing constant
if ($convolve && isset($config['convolution_constant'])) {
$img->addConvolveExpressions($config['convolution_constant']);
verbose("convolve constant = " . print_r($config['convolution_constant'], 1));
}
verbose("convolve = " . print_r($convolve, 1));
/**
* no-upscale, nu - Do not upscale smaller image to larger dimension.
*/
$upscale = getDefined(array('no-upscale', 'nu'), false, true);
verbose("upscale = $upscale");
/**
* Display image if verbose mode
*/
@@ -372,48 +608,71 @@ if ($verbose) {
unset($query['v']);
unset($query['nocache']);
unset($query['nc']);
$url1 = '?' . http_build_query($query);
$log = htmlentities(print_r(verbose(), 1));
unset($query['json']);
$url1 = '?' . htmlentities(urldecode(http_build_query($query)));
$url2 = '?' . urldecode(http_build_query($query));
echo <<<EOD
<a href=$url1><code>$url1</code></a><br>
<img src='{$url1}' />
<pre>$log</pre>
<pre id="json"></pre>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
window.getDetails = function (url, id) {
$.getJSON(url, function(data) {
element = document.getElementById(id);
element.innerHTML = "filename: " + data.filename + "\\ncolors: " + data.colors + "\\nsize: " + data.size + "\\nwidth: " + data.width + "\\nheigh: " + data.height + "\\naspect-ratio: " + data.aspectRatio;
});
}
</script>
<script type="text/javascript">window.getDetails("{$url2}&json", "json")</script>
EOD;
}
/**
* Create and output the image
* Load, process and output the image
*/
require $config['cimage_class'];
$img = new CImage();
$img->setVerbose($verbose)
$img->log("Incoming arguments: " . print_r(verbose(), 1))
->setSaveFolder($config['cache_path'])
->useCache($useCache)
->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,
// Options for calculate dimensions
'newWidth' => $newWidth,
'newHeight' => $newHeight,
'aspectRatio' => $aspectRatio,
'keepRatio' => $keepRatio,
'cropToFit' => $cropToFit,
'fillToFit' => $fillToFit,
'crop' => $crop,
'area' => $area,
'upscale' => $upscale,
// Pre-processing, before resizing is done
'scale' => $scale,
// Pre-processing, before resizing is done
'scale' => $scale,
'rotateBefore' => $rotateBefore,
'autoRotate' => $autoRotate,
// Post-processing, after resizing is done
'palette' => $palette,
'filters' => $filters,
'sharpen' => $sharpen,
'emboss' => $emboss,
'blur' => $blur,
// General processing options
'bgColor' => $bgColor,
// Post-processing, after resizing is done
'palette' => $palette,
'filters' => $filters,
'sharpen' => $sharpen,
'emboss' => $emboss,
'blur' => $blur,
'convolve' => $convolve,
'rotateAfter' => $rotateAfter,
// Output format
'outputFormat' => $outputFormat,
'dpr' => $dpr,
)
)
->loadImageDetails()
->initDimensions()
->calculateNewWidthAndHeight()
->setSaveAsExtension($saveAs)

BIN
webroot/img/car.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
webroot/img/car.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 995 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
webroot/img/issue34/3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
webroot/img/issue34/4.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 KiB

BIN
webroot/img/round8.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

BIN
webroot/img/wider.JPEG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

BIN
webroot/img/wider.JPG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

View File

@@ -1,25 +1,74 @@
<?php
/**
* Configuration for img.php, name the config file the same as your img.php and
* append _config. If you are testing out some in imgtest.php then label that
* Configuration for img.php, name the config file the same as your img.php and
* append _config. If you are testing out some in imgtest.php then label that
* config-file imgtest_config.php.
*
*/
return array(
/**
* Paths, where are all the stuff I should use?
* Append ending slash on directories.
* Where are the sources for the classfiles.
*/
'cimage_class' => __DIR__.'/../CImage.php',
'image_path' => __DIR__.'/img/',
'cache_path' => __DIR__.'/../cache/',
'autoloader' => __DIR__ . '/../autoload.php',
//'cimage_class' => __DIR__ . '/../CImage.php',
/**
* Max image dimensions,
*
* Paths, where are the images stored and where is the cache.
*/
'image_path' => __DIR__ . '/img/',
'cache_path' => __DIR__ . '/../cache/',
/**
* Check that the imagefile is a file below 'image_path' using realpath().
* Security constraint to avoid reaching images outside image_path.
* This means that symbolic links to images outside the image_path will fail.
*/
'image_path_constraint' => true,
/**
* A regexp for validating characters in the image filename.
*/
'valid_filename' => '#^[a-z0-9A-Z-/_\.:]+$#',
/**
* Allow or disallow downloading of remote files, images available on
* some remote server. Default is to disallow.
* Use password to protect from missusage, send &pwd=... or &password=..
* with the request to match the password or set to false to disable.
*
* Default values.
* remote_allow: false
* remote_password: false // as in do not use password
* remote_pattern: null // use default values from CImage
*/
//'remote_allow' => true,
//'remote_password' => false, // "secret-password",
//'remote_pattern' => '#^https?://#',
/**
* Set default timezone, it defaults to UTC if not specified.
*
*/
//'default_timezone' => 'UTC',
/**
* Max image dimensions, larger dimensions results in 404.
* This is basically a security constraint to avoid using resources on creating
* large (unwanted) images.
*
*/
'max_width' => 2000,
'max_height' => 2000,
@@ -27,8 +76,22 @@ return array(
/**
* Post processing of images using external tools, set to true or false
* and set command to be executed.
* Set default background color for all images. Override it using
* option bgColor.
* Colorvalue is 6 digit hex string between 000000-FFFFFF
* or 8 digit hex string if using the alpha channel where
* the alpha value is between 00 (opaqe) and 7F (transparent),
* that is between 00000000-FFFFFF7F.
*
*/
//'background_color' => "FFFFFF",
//'background_color' => "FFFFFF7F",
/**
* Post processing of images using external tools, set to true or false
* and set command to be executed.
*/
'postprocessing' => array(
'png_filter' => false,
@@ -44,10 +107,38 @@ return array(
/**
* Predefined size constants.
*
* Create custom convolution expressions, matrix 3x3, divisor and
* offset.
*/
'size_constant' => function() {
'convolution_constant' => array(
//'sharpen' => '-1,-1,-1, -1,16,-1, -1,-1,-1, 8, 0',
//'sharpen-alt' => '0,-1,0, -1,5,-1, 0,-1,0, 1, 0',
),
/**
* Create custom shortcuts for more advanced expressions.
*/
'shortcut' => array(
'sepia' => "&f=grayscale&f0=brightness,-10&f1=contrast,-20&f2=colorize,120,60,0,0&sharpen",
),
/**
* Predefined size constants.
*
* These can be used together with &width or &height to create a constant value
* for a width or height where can be changed in one place.
* Useful when your site changes its layout or if you have a grid to fit images into.
*
* Example:
* &width=w1 // results in width=613
* &width=c2 // results in spanning two columns with a gutter, 30*2+10=70
* &width=c24 // results in spanning whole grid 24*30+((24-1)*10)=950
*/
'size_constant' => function () {
// Set sizes to map constant to value, easier to use with width or height
$sizes = array(
@@ -55,13 +146,13 @@ return array(
'w2' => 630,
);
// Add column width to $area, useful for use as predefined size for width (or height).
// Add grid column width, useful for use as predefined size for width (or height).
$gridColumnWidth = 30;
$gridGutterWidth = 10;
$gridColumns = 24;
for ($i = 1; $i <= $gridColumns; $i++) {
$sizes['c' . $i] = ($gridColumnWidth + $gridGutterWidth) * $i - $gridGutterWidth;
$sizes['c' . $i] = ($gridColumnWidth + $gridGutterWidth) * $i - $gridGutterWidth;
}
return $sizes;
@@ -70,10 +161,10 @@ return array(
/**
* Predefined aspect ratios.
*
* Predefined aspect ratios.
*
*/
'aspect_ratio_constant' => function() {
'aspect_ratio_constant' => function () {
return array(
'3:1' => 3/1,
'3:2' => 3/2,
@@ -88,11 +179,15 @@ return array(
/**
* Set error reporting to match development or production environment
* Set error reporting to match development or production environment
*/
'error_reporting' => function() {
error_reporting(-1);
'error_reporting' => function () {
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
set_time_limit(20);
ini_set('gd.jpeg_ignore_warning', 1); // Ignore warning of corrupt jpegs
if (!extension_loaded('gd')) {
throw new Exception("Extension gd is nod loaded.");
}
},
);

163
webroot/js/cimage.js Normal file
View File

@@ -0,0 +1,163 @@
/**
* JavaScript utilities for CImage and img.php.
*/
window.CImage = (function(){
"use strict";
/**
* Init the compare page with details.
*/
function compareLoadImage(event) {
var img, json, button, area, deck, id;
id = this.dataset.id;
img = document.getElementById("img" + id);
json = document.getElementById("json" + id);
button = document.getElementById("button" + id);
area = document.getElementById("area" + id);
deck = document.getElementById("deck" + id);
if (this.value == "") {
// Clear image if input is cleared
button.setAttribute("disabled", "disabled");
area.classList.add("hidden");
button.classList.remove("selected");
return;
}
// Display image in its area
img.src = this.value;
area.classList.remove("hidden");
$.getJSON(this.value + "&json", function(data) {
json.innerHTML = "filename: " + data.filename + "\ncolors: " + data.colors + "\nsize: " + data.size + "\nwidth: " + data.width + "\nheigh: " + data.height + "\naspect-ratio: " + data.aspectRatio;
});
// Display image in overlay
button.removeAttribute("disabled");
button.classList.add("selected");
};
/**
* Init the compare page with details.
*/
function compareInit(options)
{
var elements, id, onTop, myEvent,
input1 = document.getElementById("input1"),
input2 = document.getElementById("input2"),
input3 = document.getElementById("input3"),
input4 = document.getElementById("input4"),
details = document.getElementById("viewDetails"),
stack = document.getElementById("stack"),
buttons = document.getElementById("buttonWrap");
/* img1 = document.getElementById("img1"),
img2 = document.getElementById("img2"),
img3 = document.getElementById("img3"),
img4 = document.getElementById("img4"),
img01 = document.getElementById("img01"),
img02 = document.getElementById("img02"),
img03 = document.getElementById("img03"),
img04 = document.getElementById("img04"),
json1 = document.getElementById("json1"),
json2 = document.getElementById("json2"),
json3 = document.getElementById("json3"),
json4 = document.getElementById("json4"),
json01 = document.getElementById("json01"),
json02 = document.getElementById("json02"),
json03 = document.getElementById("json03"),
json04 = document.getElementById("json04"),
button1 = document.getElementById("button1"),
button2 = document.getElementById("button2"),
button3 = document.getElementById("button3"),
button4 = document.getElementById("button4"),
area1 = document.getElementById("area1"),
area2 = document.getElementById("area2"),
area3 = document.getElementById("area3"),
area4 = document.getElementById("area4");*/
input1.addEventListener("change", compareLoadImage);
input2.addEventListener("change", compareLoadImage);
input3.addEventListener("change", compareLoadImage);
input4.addEventListener("change", compareLoadImage);
// Toggle json
details.addEventListener("change", function() {
var elements = document.querySelectorAll(".json");
for (var element of elements) {
element.classList.toggle("hidden");
}
});
// Do not show json as default
if (options.json === false) {
details.setAttribute("checked", "checked");
myEvent = new CustomEvent("change");
details.dispatchEvent(myEvent);
}
// Toggle stack
stack.addEventListener("change", function() {
var element,
elements = document.querySelectorAll(".area");
buttons.classList.toggle("hidden");
for (element of elements) {
element.classList.toggle("stack");
if (!element.classList.contains('hidden')) {
onTop = element;
}
}
onTop.classList.toggle("top");
console.log("Stacking");
});
// Stack as default
if (options.stack === true) {
stack.setAttribute("checked", "checked");
myEvent = new CustomEvent("change");
stack.dispatchEvent(myEvent);
}
// Button clicks
elements = document.querySelectorAll(".button");
for (var element of elements) {
element.addEventListener("click", function() {
var id = this.dataset.id,
area = document.getElementById("area" + id);
area.classList.toggle("top");
onTop.classList.toggle("top");
onTop = area;
console.log("button" + id);
});
}
input1.value = options.input1 || null;
input2.value = options.input2 || null;
input3.value = options.input3 || null;
input4.value = options.input4 || null;
compareLoadImage.call(input1);
compareLoadImage.call(input2);
compareLoadImage.call(input3);
compareLoadImage.call(input4);
console.log(options);
}
return {
"compare": compareInit
};
}());

8
webroot/test/config.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
// Use error reporting
error_reporting(-1);
ini_set('display_errors', 1);
// The link to img.php
$imgphp = "../img.php?src=";

101
webroot/test/template.php Normal file
View File

@@ -0,0 +1,101 @@
<!doctype html>
<head>
<meta charset='utf-8'/>
<title><?=$title?></title>
<style>
body {background-color: #ccc;}
</style>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
window.getDetails = function (url, id) {
$.getJSON(url, function(data) {
element = document.getElementById(id);
element.innerHTML = "filename: " + data.filename + "\ncolors: " + data.colors + "\nsize: " + data.size + "\nwidth: " + data.width + "\nheigh: " + data.height + "\naspect-ratio: " + data.aspectRatio;
});
}
</script>
</head>
<body>
<h1><?=$title?></h1>
<?php if (isset($description)) : ?>
<p><?=$description?></p>
<?php endif; ?>
<h2>Images used in test</h2>
<p>The following images are used for this test.</p>
<?php foreach($images as $image) : ?>
<p>
<code>
<a href="img/<?=$image?>"><?=$image?></a>
<a href="<?=$imgphp . $image . '&json'?>">(json)</a>
<a href="<?=$imgphp . $image . '&verbose'?>">(verbose)</a>
</code>
<br>
<img src="<?=$imgphp . $image?>"></p>
<p></p>
<pre id="<?=$image?>"></pre>
<script type="text/javascript">window.getDetails("<?=$imgphp . $image . '&json'?>", "<?=$image?>")</script>
<?php endforeach; ?>
<h2>Testcases used for each image</h2>
<p>The following testcases are used for each image.</p>
<?php foreach($testcase as $tc) : ?>
<code><?=$tc?></code><br>
<?php endforeach; ?>
<h2>For each image, apply all testcases</h2>
<?php
$ch1 = 1;
foreach($images as $image) :
?>
<h3><?=$ch1?>. Using source image <?=$image?></h3>
<p>
<code>
<a href="img/<?=$image?>"><?=$image?></a>
<a href="<?=$imgphp . $image . '&json'?>">(json)</a>
<a href="<?=$imgphp . $image . '&verbose'?>">(verbose)</a>
</code>
<br>
<img src="<?=$imgphp . $image?>">
</p>
<pre id="<?=$ch1?>"></pre>
<script type="text/javascript">window.getDetails("<?=$imgphp . $image . '&json'?>", "<?=$ch1?>")</script>
<?php
$ch2 = 1;
foreach($testcase as $tc) :
$tcId = "$ch1.$ch2";
?>
<h4>Testcase <?=$tcId?>: <?=$tc?></h4>
<p>
<code>
<a href="<?=$imgphp . $image . $tc?>"><?=$image . $tc?></a>
<a href="<?=$imgphp . $image . $tc . '&json'?>">(json)</a>
<a href="<?=$imgphp . $image . $tc . '&verbose'?>">(verbose)</a>
</code>
<br>
<img src="<?=$imgphp . $image . $tc?>">
</p>
<pre id="<?=$tcId?>"></pre>
<script type="text/javascript">window.getDetails("<?=$imgphp . $image . $tc . '&json'?>", "<?=$tcId?>")</script>
<?php $ch2++; endforeach; ?>
<?php $ch1++; endforeach; ?>

View File

@@ -5,25 +5,6 @@
</head>
<body>
<h1>Testing <code>CImage.php</code> through <code>img.php</code></h1>
<p>You can test any variation of resizing the images through <a href='img.php?src=wider.jpg&amp;w=200&amp;h=200'>img.php?src=wider.jpg&amp;w=200&amp;h=200</a> or <a href='img.php?src=higher.jpg&amp;w=200&amp;h=200'>img.php?src=higher.jpg&amp;w=200&amp;h=200</a></p>
<p>Supported arguments throught the querystring are:</p>
<ul>
<li>h, height: h=200 sets the new height to max 200px.
<li>w, width: w=200 sets the new width to max 200px.
<li>crop-to-fit: set together with both h & w to make the image fit in the box and crop out the rest.
<li>no-ratio: do not keep aspect ratio.
<li>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.
<li>q, quality: q=70 or quality=70 sets the image quality as value between 0 and 100, default is full quality/100.
<li>f, filter: apply filter to image, f=colorize,0,255,0,0 makes image greener. Supports all filters as defined in <a href='http://php.net/manual/en/function.imagefilter.php'><code>imagefilter()</code></a>
<li>f0-f9: same as f/filter, just add more filters. Applied in order f, f0-f9.
</ul>
<p>Supports <code>.jpg</code>, <code>.png</code> and <code>.gif</code>.</p>
<p>Sourcecode and issues on github: <a href='https://github.com/mosbth/cimage'>https://github.com/mosbth/cimage</a></p>
<p>Copyright 2012, Mikael Roos (mos@dbwebb.se)</p>
<h2>Testcases</h2>
@@ -66,7 +47,7 @@ $testcase = array(
<tbody>
<?php
foreach($testcase as $key => $val) {
$url = "img.php?src=wider.jpg{$val['query']}";
$url = "../img.php?src=wider.jpg{$val['query']}";
echo "<tr><td id=w$key><a href=#w$key>$key</a></br>{$val['text']}</br><code><a href='$url'>".htmlentities($url)."</a></code></td><td><img src='$url' /></td></tr>";
}
?>
@@ -80,7 +61,7 @@ foreach($testcase as $key => $val) {
<tbody>
<?php
foreach($testcase as $key => $val) {
$url = "img.php?src=higher.jpg{$val['query']}";
$url = "../img.php?src=higher.jpg{$val['query']}";
echo "<tr><td id=h$key><a href=#h$key>$key</a></br>{$val['text']}</br><code><a href='$url'>".htmlentities($url)."</a></code></td><td><img src='$url' /></td></tr>";
}
?>

View File

@@ -0,0 +1,38 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing img for issue 29";
// Provide a short description of the testcase.
$description = "";
// Use these images in the test
$images = array(
'issue29/400x265.jpg',
'issue29/400x268.jpg',
'issue29/400x300.jpg',
'issue29/465x304.jpg',
'issue29/640x273.jpg',
);
// For each image, apply these testcases
$testcase = array(
'&w=300&cf&q=80&nc',
'&w=75&h=75&cf&q=80&nc',
'&w=75&h=75&q=80',
);
// Applu testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,42 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 36 - autoRotate";
// Provide a short description of the testcase.
$description = "";
// Use these images in the test
$images = array(
'issue36/me-0.jpg',
'issue36/me-90.jpg',
'issue36/me-180.jpg',
'issue36/me-270.jpg',
'issue36/flower-0.jpg',
'issue36/flower-90.jpg',
'issue36/flower-180.jpg',
'issue36/flower-270.jpg',
);
// For each image, apply these testcases
$testcase = array(
'&aro&nc',
'&aro&nc&w=200',
'&aro&nc&h=200',
'&aro&nc&w=200&h=200&cf',
);
// Applu testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,42 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$angle = 180;
$title = "Testing img for issue 36 - rotateBefore, rotateAfter <?=$angle?>";
// Provide a short description of the testcase.
$description = "";
// Use these images in the test
$images = array(
'kodim08.png',
'kodim04.png',
);
// For each image, apply these testcases
$testcase = array(
"&rb=$angle&nc",
"&rb=$angle&nc&w=200",
"&rb=$angle&nc&h=200",
"&rb=$angle&nc&w=200&h=200&cf",
"&ra=$angle&nc",
"&ra=$angle&nc&w=200",
"&ra=$angle&nc&h=200",
"&ra=$angle&nc&w=200&h=200&cf",
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,42 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$angle = 270;
$title = "Testing img for issue 36 - rotateBefore, rotateAfter <?=$angle?>";
// Provide a short description of the testcase.
$description = "";
// Use these images in the test
$images = array(
'kodim08.png',
'kodim04.png',
);
// For each image, apply these testcases
$testcase = array(
"&rb=$angle&nc",
"&rb=$angle&nc&w=200",
"&rb=$angle&nc&h=200",
"&rb=$angle&nc&w=200&h=200&cf",
"&ra=$angle&nc",
"&ra=$angle&nc&w=200",
"&ra=$angle&nc&h=200",
"&ra=$angle&nc&w=200&h=200&cf",
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,42 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$angle = 45;
$title = "Testing img for issue 36 - rotateBefore, rotateAfter <?=$angle?>";
// Provide a short description of the testcase.
$description = "";
// Use these images in the test
$images = array(
'kodim08.png',
'kodim04.png',
);
// For each image, apply these testcases
$testcase = array(
"&rb=$angle&nc",
"&rb=$angle&nc&w=200",
"&rb=$angle&nc&h=200",
"&rb=$angle&nc&w=200&h=200&cf",
"&ra=$angle&nc",
"&ra=$angle&nc&w=200",
"&ra=$angle&nc&h=200",
"&ra=$angle&nc&w=200&h=200&cf",
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,42 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$angle = 90;
$title = "Testing img for issue 36 - rotateBefore, rotateAfter <?=$angle?>";
// Provide a short description of the testcase.
$description = "";
// Use these images in the test
$images = array(
'kodim08.png',
'kodim04.png',
);
// For each image, apply these testcases
$testcase = array(
"&rb=$angle&nc",
"&rb=$angle&nc&w=200",
"&rb=$angle&nc&h=200",
"&rb=$angle&nc&w=200&h=200&cf",
"&ra=$angle&nc",
"&ra=$angle&nc&w=200",
"&ra=$angle&nc&h=200",
"&ra=$angle&nc&w=200&h=200&cf",
);
// Applu testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,43 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 38 - fill to fit, together with background colors";
// Provide a short description of the testcase.
$description = "The issue was to implement fill-to-fit, but it needs some flexibility in how to choose the background color and it also affects rotation of the image (the background color does). So this testcase is both for fill-to-fit and for background color (thereby including a test using rotate).";
// Use these images in the test
$images = array(
'kodim04.png',
);
// For each image, apply these testcases
$cache = "&nc"; // ""; // "&nc"
$testcase = array(
"$cache&w=300&h=300&fill-to-fit",
"$cache&w=200&h=400&fill-to-fit",
"$cache&w=300&h=300&fill-to-fit=ff0000",
"$cache&w=200&h=400&fill-to-fit=ff0000",
"$cache&w=300&h=300&fill-to-fit=ff00003f",
"$cache&w=200&h=400&fill-to-fit=ff00003f",
"$cache&w=200&h=400&fill-to-fit&bgc=ff0000",
"$cache&w=300&h=300&fill-to-fit&bgc=ff00003f",
"$cache&w=300&h=300&ra=45",
"$cache&w=300&h=300&ra=45&bgc=ff0000",
"$cache&w=300&h=300&ra=45&bgc=ff00003f",
);
// Applu testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,37 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 40 - no ratio";
// Provide a short description of the testcase.
$description = "Showing off how to resize image with and without ratio.";
// Use these images in the test
$images = array(
'issue40/source.jpg',
);
// For each image, apply these testcases
$testcase = array(
'&nc&width=652&height=466',
'&nc&width=652&height=466&no-ratio',
'&nc&width=652&height=466&crop-to-fit',
'&nc&width=652&aspect-ratio=1.4',
'&nc&width=652&aspect-ratio=1.4&no-ratio',
'&nc&width=652&aspect-ratio=1.4&crop-to-fit',
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,38 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 49 - flexible convolution";
// Provide a short description of the testcase.
$description = "Creating shortcuts to custom convolutions by using configurable list of constant convolutions.";
// Use these images in the test
$images = array(
'kodim08.png',
);
// For each image, apply these testcases
$testcase = array(
'&nc&width=400&convolve=lighten',
'&nc&width=400&convolve=darken',
'&nc&width=400&convolve=sharpen',
'&nc&width=400&convolve=emboss',
'&nc&width=400&convolve=blur',
'&nc&width=400&convolve=blur:blur',
'&nc&width=400&convolve=blur:blur:blur:blur',
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,41 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 52 - Fill to fit fails with aspect ratio";
// Provide a short description of the testcase.
$description = "Verify that Fill To Fit resize strategy works with all variants of sizes.";
// Use these images in the test
$images = array(
'car.png',
);
// For each image, apply these testcases
$nc = '&nc';
$testcase = array(
$nc . '&w=300&h=300&crop-to-fit',
$nc . '&w=300&ar=1&crop-to-fit',
$nc . '&w=300&ar=3&crop-to-fit',
$nc . '&h=300&ar=1&crop-to-fit',
$nc . '&h=300&ar=3&crop-to-fit',
$nc . '&w=50%&ar=1&crop-to-fit',
$nc . '&w=50%&ar=3&crop-to-fit',
$nc . '&h=50%&ar=1&crop-to-fit',
$nc . '&h=50%&ar=3&crop-to-fit',
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,41 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 52 - Fill to fit fails with aspect ratio";
// Provide a short description of the testcase.
$description = "Verify that Fill To Fit resize strategy works with all variants of sizes.";
// Use these images in the test
$images = array(
'car.png',
);
// For each image, apply these testcases
$nc = '&nc';
$testcase = array(
$nc . '&w=300&h=300&stretch',
$nc . '&w=300&ar=1&stretch',
$nc . '&w=300&ar=3&stretch',
$nc . '&h=300&ar=1&stretch',
$nc . '&h=300&ar=3&stretch',
$nc . '&w=50%&ar=1&stretch',
$nc . '&w=50%&ar=3&stretch',
$nc . '&h=50%&ar=1&stretch',
$nc . '&h=50%&ar=3&stretch',
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,41 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 52 - Fill to fit fails with aspect ratio";
// Provide a short description of the testcase.
$description = "Verify that Fill To Fit resize strategy works with all variants of sizes.";
// Use these images in the test
$images = array(
'car.png',
);
// For each image, apply these testcases
$nc = null; //&nc';
$testcase = array(
$nc . '&w=300&h=300&fill-to-fit',
$nc . '&w=300&ar=1&fill-to-fit',
$nc . '&w=300&ar=2&fill-to-fit',
$nc . '&h=300&ar=1&fill-to-fit',
$nc . '&h=300&ar=2&fill-to-fit',
$nc . '&w=50%&ar=1&fill-to-fit',
$nc . '&w=50%&ar=2&fill-to-fit',
$nc . '&h=50%&ar=1&fill-to-fit',
$nc . '&h=50%&ar=2&fill-to-fit',
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,36 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 58 - JSON reporting filesize";
// Provide a short description of the testcase.
$description = "Verify that JSON returns filesize of actual image.";
// Use these images in the test
$images = array(
'kodim08.png',
);
// For each image, apply these testcases
$testcase = array(
'&w=300',
'&w=300&h=300',
'&w=300&h=300&stretch',
'&w=300&h=300&crop-to-fit',
'&w=300&h=300&fill-to-fit',
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,33 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing issue 60 - skip original";
// Provide a short description of the testcase.
$description = "Always use the original if suitable, use skip-original to force using the cached version.";
// Use these images in the test
$images = array(
'car.png',
);
// For each image, apply these testcases
$testcase = array(
'',
'&so',
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,41 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing option crop";
// Provide a short description of the testcase.
$description = "Cropping parts of image";
// Use these images in the test
$images = array(
'kodim04.png',
);
// For each image, apply these testcases
$nc = "&nc"; //null; //&nc';
$testcase = array(
$nc . '&w=300',
$nc . '&w=300&crop=0,0,0,0',
$nc . '&crop=300,200,0,0',
$nc . '&crop=300,200,left,top',
$nc . '&crop=300,200,right,top',
$nc . '&crop=300,200,right,bottom',
$nc . '&crop=300,200,left,bottom',
$nc . '&crop=300,200,center,center',
$nc . '&crop=200,220,190,300',
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,58 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing option no-upscale";
// Provide a short description of the testcase.
$description = "Do not upscale image when original image (slice) is smaller than target image.";
// Use these images in the test
$images = array(
'car.png',
);
// For each image, apply these testcases
$nc = null; //"&nc"; //null; //&nc';
$testcase = array(
$nc . '&w=600',
$nc . '&w=600&no-upscale',
$nc . '&h=400',
$nc . '&h=400&no-upscale',
$nc . '&w=600&h=400',
$nc . '&w=600&h=400&no-upscale',
$nc . '&w=700&h=400&stretch',
$nc . '&w=700&h=400&no-upscale&stretch',
$nc . '&w=700&h=200&stretch',
$nc . '&w=700&h=200&no-upscale&stretch',
$nc . '&w=300&h=400&stretch',
$nc . '&w=300&h=400&no-upscale&stretch',
$nc . '&w=600&h=400&crop-to-fit',
$nc . '&w=600&h=400&no-upscale&crop-to-fit',
$nc . '&w=600&h=200&crop-to-fit',
$nc . '&w=600&h=200&no-upscale&crop-to-fit',
$nc . '&w=300&h=400&crop-to-fit',
$nc . '&w=300&h=400&no-upscale&crop-to-fit',
$nc . '&w=600&h=400&fill-to-fit',
$nc . '&w=600&h=400&no-upscale&fill-to-fit',
/*
$nc . '&w=600&ar=1.6',
$nc . '&w=600&ar=1.6&no-upscale',
$nc . '&h=400&ar=1.6',
$nc . '&h=400&ar=1.6&no-upscale',
*/
);
// Apply testcases and present results
include __DIR__ . "/template.php";

View File

@@ -0,0 +1,42 @@
<?php
// Include config for all testcases
include __DIR__ . "/config.php";
// The title of the test case
$title = "Testing option save-as - save image to another format";
// Provide a short description of the testcase.
$description = "";
// Use these images in the test
$images = array(
'car.png',
'car.gif',
'car.jpg',
'ball24.png',
'wider.jpg',
);
// For each image, apply these testcases
$nc = "&nc"; //null; //&nc';
$testcase = array(
$nc . '&w=300',
$nc . '&w=300&sa=jpg',
$nc . '&w=300&sa=png',
$nc . '&w=300&sa=gif',
$nc . '&w=300&palette',
$nc . '&w=300&sa=png&palette',
);
// Apply testcases and present results
include __DIR__ . "/template.php";