mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-07 08:36:32 +02:00
Merge branch '078'
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -4,3 +4,7 @@ cache/*
|
|||||||
# Test
|
# Test
|
||||||
coverage/
|
coverage/
|
||||||
coverage.clover
|
coverage.clover
|
||||||
|
|
||||||
|
# Composer
|
||||||
|
composer.lock
|
||||||
|
vendor
|
||||||
|
105
CImage.php
105
CImage.php
@@ -626,7 +626,7 @@ class CImage
|
|||||||
private function normalizeFileExtension($extension = null)
|
private function normalizeFileExtension($extension = null)
|
||||||
{
|
{
|
||||||
$extension = strtolower($extension ? $extension : $this->extension);
|
$extension = strtolower($extension ? $extension : $this->extension);
|
||||||
|
|
||||||
if ($extension == 'jpeg') {
|
if ($extension == 'jpeg') {
|
||||||
$extension = 'jpg';
|
$extension = 'jpg';
|
||||||
}
|
}
|
||||||
@@ -648,7 +648,7 @@ class CImage
|
|||||||
if (!$this->isRemoteSourceOnWhitelist($src)) {
|
if (!$this->isRemoteSourceOnWhitelist($src)) {
|
||||||
throw new Exception("Hostname is not on whitelist for remote sources.");
|
throw new Exception("Hostname is not on whitelist for remote sources.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$remote = new CRemoteImage();
|
$remote = new CRemoteImage();
|
||||||
$cache = $this->saveFolder . "/remote/";
|
$cache = $this->saveFolder . "/remote/";
|
||||||
|
|
||||||
@@ -1298,10 +1298,11 @@ class CImage
|
|||||||
* @param string $base as optional basepath for storing file.
|
* @param string $base as optional basepath for storing file.
|
||||||
* @param boolean $useSubdir use or skip the subdir part when creating the
|
* @param boolean $useSubdir use or skip the subdir part when creating the
|
||||||
* filename.
|
* filename.
|
||||||
|
* @param string $prefix to add as part of filename
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function generateFilename($base = null, $useSubdir = true)
|
public function generateFilename($base = null, $useSubdir = true, $prefix = null)
|
||||||
{
|
{
|
||||||
$filename = basename($this->pathToImage);
|
$filename = basename($this->pathToImage);
|
||||||
$cropToFit = $this->cropToFit ? '_cf' : null;
|
$cropToFit = $this->cropToFit ? '_cf' : null;
|
||||||
@@ -1322,9 +1323,9 @@ class CImage
|
|||||||
if ($this->copyStrategy === self::RESIZE) {
|
if ($this->copyStrategy === self::RESIZE) {
|
||||||
$copyStrat = "_rs";
|
$copyStrat = "_rs";
|
||||||
}
|
}
|
||||||
|
|
||||||
$width = $this->newWidth;
|
$width = $this->newWidth ? '_' . $this->newWidth : null;
|
||||||
$height = $this->newHeight;
|
$height = $this->newHeight ? '_' . $this->newHeight : null;
|
||||||
|
|
||||||
$offset = isset($this->offset)
|
$offset = isset($this->offset)
|
||||||
? '_o' . $this->offset['top'] . '-' . $this->offset['right'] . '-' . $this->offset['bottom'] . '-' . $this->offset['left']
|
? '_o' . $this->offset['top'] . '-' . $this->offset['right'] . '-' . $this->offset['bottom'] . '-' . $this->offset['left']
|
||||||
@@ -1373,9 +1374,9 @@ class CImage
|
|||||||
$subdir = ($subdir == '.') ? '_.' : $subdir;
|
$subdir = ($subdir == '.') ? '_.' : $subdir;
|
||||||
$subdir .= '_';
|
$subdir .= '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $subdir . $filename . '_' . $width . '_'
|
$file = $prefix . $subdir . $filename . $width . $height
|
||||||
. $height . $offset . $crop . $cropToFit . $fillToFit
|
. $offset . $crop . $cropToFit . $fillToFit
|
||||||
. $crop_x . $crop_y . $upscale
|
. $crop_x . $crop_y . $upscale
|
||||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||||
. $optimize . $compress
|
. $optimize . $compress
|
||||||
@@ -1444,7 +1445,7 @@ class CImage
|
|||||||
if ($this->image === false) {
|
if ($this->image === false) {
|
||||||
throw new Exception("Could not load image.");
|
throw new Exception("Could not load image.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Removed v0.7.7
|
/* Removed v0.7.7
|
||||||
if (image_type_to_mime_type($this->fileType) == 'image/png') {
|
if (image_type_to_mime_type($this->fileType) == 'image/png') {
|
||||||
$type = $this->getPngType();
|
$type = $this->getPngType();
|
||||||
@@ -1484,14 +1485,14 @@ class CImage
|
|||||||
public function getPngType($filename = null)
|
public function getPngType($filename = null)
|
||||||
{
|
{
|
||||||
$filename = $filename ? $filename : $this->pathToImage;
|
$filename = $filename ? $filename : $this->pathToImage;
|
||||||
|
|
||||||
$pngType = ord(file_get_contents($filename, false, null, 25, 1));
|
$pngType = ord(file_get_contents($filename, false, null, 25, 1));
|
||||||
|
|
||||||
if ($this->verbose) {
|
if ($this->verbose) {
|
||||||
$this->log("Checking png type of: " . $filename);
|
$this->log("Checking png type of: " . $filename);
|
||||||
$this->log($this->getPngTypeAsString($pngType));
|
$this->log($this->getPngTypeAsString($pngType));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pngType;
|
return $pngType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1515,7 +1516,7 @@ class CImage
|
|||||||
$index = imagecolortransparent($this->image);
|
$index = imagecolortransparent($this->image);
|
||||||
$transparent = null;
|
$transparent = null;
|
||||||
if ($index != -1) {
|
if ($index != -1) {
|
||||||
$transparent = " (transparent)";
|
$transparent = " (transparent)";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($pngType) {
|
switch ($pngType) {
|
||||||
@@ -2222,7 +2223,7 @@ class CImage
|
|||||||
$index = $this->image
|
$index = $this->image
|
||||||
? imagecolortransparent($this->image)
|
? imagecolortransparent($this->image)
|
||||||
: -1;
|
: -1;
|
||||||
|
|
||||||
if ($index != -1) {
|
if ($index != -1) {
|
||||||
|
|
||||||
imagealphablending($img, true);
|
imagealphablending($img, true);
|
||||||
@@ -2290,8 +2291,8 @@ class CImage
|
|||||||
return substr(image_type_to_extension($this->fileType), 1);
|
return substr(image_type_to_extension($this->fileType), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save image.
|
* Save image.
|
||||||
@@ -2397,6 +2398,74 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert image from one colorpsace/color profile to sRGB without
|
||||||
|
* color profile.
|
||||||
|
*
|
||||||
|
* @param string $src of image.
|
||||||
|
* @param string $dir as base directory where images are.
|
||||||
|
* @param string $cache as base directory where to store images.
|
||||||
|
* @param string $iccFile filename of colorprofile.
|
||||||
|
* @param boolean $useCache or not, default to always use cache.
|
||||||
|
*
|
||||||
|
* @return string | boolean false if no conversion else the converted
|
||||||
|
* filename.
|
||||||
|
*/
|
||||||
|
public function convert2sRGBColorSpace($src, $dir, $cache, $iccFile, $useCache = true)
|
||||||
|
{
|
||||||
|
if ($this->verbose) {
|
||||||
|
$this->log("# Converting image to sRGB colorspace.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists("Imagick")) {
|
||||||
|
$this->log(" Ignoring since Imagemagick is not installed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare
|
||||||
|
$this->setSaveFolder($cache)
|
||||||
|
->setSource($src, $dir)
|
||||||
|
->generateFilename(null, false, 'srgb_');
|
||||||
|
|
||||||
|
// Check if the cached version is accurate.
|
||||||
|
if ($useCache && is_readable($this->cacheFileName)) {
|
||||||
|
$fileTime = filemtime($this->pathToImage);
|
||||||
|
$cacheTime = filemtime($this->cacheFileName);
|
||||||
|
|
||||||
|
if ($fileTime <= $cacheTime) {
|
||||||
|
$this->log(" Using cached version: " . $this->cacheFileName);
|
||||||
|
return $this->cacheFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only covert if cachedir is writable
|
||||||
|
if (is_writable($this->saveFolder)) {
|
||||||
|
// Load file and check if conversion is needed
|
||||||
|
$image = new Imagick($this->pathToImage);
|
||||||
|
$colorspace = $image->getImageColorspace();
|
||||||
|
$this->log(" Current colorspace: " . $colorspace);
|
||||||
|
|
||||||
|
$profiles = $image->getImageProfiles('*', false);
|
||||||
|
$hasICCProfile = (array_search('icc', $profiles) !== false);
|
||||||
|
$this->log(" Has ICC color profile: " . ($hasICCProfile ? "YES" : "NO"));
|
||||||
|
|
||||||
|
if ($colorspace != Imagick::COLORSPACE_SRGB || $hasICCProfile) {
|
||||||
|
$this->log(" Converting to sRGB.");
|
||||||
|
|
||||||
|
$sRGBicc = file_get_contents($iccFile);
|
||||||
|
$image->profileImage('icc', $sRGBicc);
|
||||||
|
|
||||||
|
$image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
|
||||||
|
$image->writeImage($this->cacheFileName);
|
||||||
|
return $this->cacheFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a hard link, as an alias, to the cached file.
|
* Create a hard link, as an alias, to the cached file.
|
||||||
*
|
*
|
||||||
@@ -2514,7 +2583,7 @@ class CImage
|
|||||||
$this->log("Content-type: " . $mime);
|
$this->log("Content-type: " . $mime);
|
||||||
$this->log("Content-length: " . $size);
|
$this->log("Content-length: " . $size);
|
||||||
$this->verboseOutput();
|
$this->verboseOutput();
|
||||||
|
|
||||||
if (is_null($this->verboseFileName)) {
|
if (is_null($this->verboseFileName)) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@@ -2566,7 +2635,7 @@ class CImage
|
|||||||
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
||||||
$details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB";
|
$details['memoryCurrent'] = round(memory_get_usage()/1024/1024, 3) . " MB";
|
||||||
$details['memoryLimit'] = ini_get('memory_limit');
|
$details['memoryLimit'] = ini_get('memory_limit');
|
||||||
|
|
||||||
if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
|
if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
|
||||||
$details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s";
|
$details['loadTime'] = (string) round((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), 3) . "s";
|
||||||
}
|
}
|
||||||
|
@@ -5,12 +5,15 @@ Revision history
|
|||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
||||||
|
|
||||||
|
|
||||||
v0.7.7* (2015-10-25)
|
v0.7.8 (2015-12-06)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
|
* HTTP error messages now 403, 404 and 500 as in #128 and #127.
|
||||||
* More examples on dealing with cache through bash `bin/cache.bash`, #129.
|
* More examples on dealing with cache through bash `bin/cache.bash`, #129.
|
||||||
|
* Added conversion to sRGB using option `?srgb`. #120.
|
||||||
* Added Gitter badge to README, #126.
|
* Added Gitter badge to README, #126.
|
||||||
* Fix proper download url in README, #125.
|
* Fix proper download url in README, #125.
|
||||||
|
* Change path in `webroot/htaccess` to make it work in current environment.
|
||||||
|
|
||||||
|
|
||||||
v0.7.7 (2015-10-21)
|
v0.7.7 (2015-10-21)
|
||||||
|
BIN
icc/sRGB_IEC61966-2-1_black_scaled.icc
Normal file
BIN
icc/sRGB_IEC61966-2-1_black_scaled.icc
Normal file
Binary file not shown.
74
test/CImageSRGBTest.php
Normal file
74
test/CImageSRGBTest.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A testclass
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CImageSRGBTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
private $srgbDir = "srgb";
|
||||||
|
private $cache;
|
||||||
|
private $srgbColorProfile;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup before test
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->srgbColorProfile = __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc';
|
||||||
|
$this->cache = CACHE_PATH . "/" . $this->srgbDir;
|
||||||
|
|
||||||
|
if (!is_writable($this->cache)) {
|
||||||
|
mkdir($this->cache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCreate1()
|
||||||
|
{
|
||||||
|
$img = new CImage();
|
||||||
|
|
||||||
|
$filename = $img->convert2sRGBColorSpace(
|
||||||
|
'car.png',
|
||||||
|
IMAGE_PATH,
|
||||||
|
$this->cache,
|
||||||
|
$this->srgbColorProfile
|
||||||
|
);
|
||||||
|
|
||||||
|
if (class_exists("Imagick")) {
|
||||||
|
$this->assertEquals("srgb_car.png", basename($filename), "Filename not as expected on image.");
|
||||||
|
} else {
|
||||||
|
$this->assertFalse($filename, "ImageMagick not installed, silent fail");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCreate2()
|
||||||
|
{
|
||||||
|
$img = new CImage();
|
||||||
|
|
||||||
|
$filename = $img->convert2sRGBColorSpace(
|
||||||
|
'car.jpg',
|
||||||
|
IMAGE_PATH,
|
||||||
|
$this->cache,
|
||||||
|
$this->srgbColorProfile
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertFalse($filename);
|
||||||
|
}
|
||||||
|
}
|
@@ -10,6 +10,9 @@ echo "Extension exif is $no loaded.<br>";
|
|||||||
$no = extension_loaded('curl') ? null : 'NOT';
|
$no = extension_loaded('curl') ? null : 'NOT';
|
||||||
echo "Extension curl is $no loaded.<br>";
|
echo "Extension curl is $no loaded.<br>";
|
||||||
|
|
||||||
|
$no = extension_loaded('imagick') ? null : 'NOT';
|
||||||
|
echo "Extension imagick is $no loaded.<br>";
|
||||||
|
|
||||||
$no = extension_loaded('gd') ? null : 'NOT';
|
$no = extension_loaded('gd') ? null : 'NOT';
|
||||||
echo "Extension gd is $no loaded.<br>";
|
echo "Extension gd is $no loaded.<br>";
|
||||||
|
|
||||||
|
@@ -5,7 +5,6 @@
|
|||||||
#
|
#
|
||||||
# img A directory where all images are stored
|
# img A directory where all images are stored
|
||||||
# img/me.jpg Access a image as usually.
|
# 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 Access a image though img.php using htaccess rewrite.
|
||||||
# image/me.jpg?w=300 Using options to img.php.
|
# image/me.jpg?w=300 Using options to img.php.
|
||||||
#
|
#
|
||||||
@@ -15,4 +14,4 @@
|
|||||||
# image/me/me.jpg?w=300 Using options to img.php.
|
# image/me/me.jpg?w=300 Using options to img.php.
|
||||||
#
|
#
|
||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
RewriteRule ^image/(.*)$ img/img.php?src=$1 [QSA,NC,L]
|
RewriteRule ^image/(.*)$ img.php?src=$1 [QSA,NC,L]
|
||||||
|
@@ -643,6 +643,12 @@ verbose("area = $area");
|
|||||||
* skip-original, so - skip the original image and always process a new image
|
* skip-original, so - skip the original image and always process a new image
|
||||||
*/
|
*/
|
||||||
$useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
$useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
||||||
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
|
if ($useOriginalDefault === true) {
|
||||||
|
verbose("use original is default ON");
|
||||||
|
$useOriginal = true;
|
||||||
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
|
||||||
@@ -984,6 +990,42 @@ if ($dummyImage === true) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare a sRGB version of the image and use it as source image.
|
||||||
|
*/
|
||||||
|
$srgbDirName = "/srgb";
|
||||||
|
$srgbDir = realpath(getConfig('srgb_dir', $cachePath . $srgbDirName));
|
||||||
|
$srgbDefault = getConfig('srgb_default', false);
|
||||||
|
$srgbColorProfile = getConfig('srgb_colorprofile', __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc');
|
||||||
|
$srgb = getDefined('srgb', true, null);
|
||||||
|
|
||||||
|
if ($srgb || $srgbDefault) {
|
||||||
|
|
||||||
|
if (!is_writable($srgbDir)) {
|
||||||
|
if (is_writable($cachePath)) {
|
||||||
|
mkdir($srgbDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = $img->convert2sRGBColorSpace(
|
||||||
|
$srcImage,
|
||||||
|
$imagePath,
|
||||||
|
$srgbDir,
|
||||||
|
$srgbColorProfile,
|
||||||
|
$useCache
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($filename) {
|
||||||
|
$srcImage = $img->getTarget();
|
||||||
|
$imagePath = null;
|
||||||
|
verbose("srgb conversion and saved to cache = $srcImage");
|
||||||
|
} else {
|
||||||
|
verbose("srgb not op");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display status
|
* Display status
|
||||||
*/
|
*/
|
||||||
@@ -994,6 +1036,7 @@ if ($status) {
|
|||||||
$text .= "Allow remote images = $allowRemote\n";
|
$text .= "Allow remote images = $allowRemote\n";
|
||||||
$text .= "Cache writable = " . is_writable($cachePath) . "\n";
|
$text .= "Cache writable = " . is_writable($cachePath) . "\n";
|
||||||
$text .= "Cache dummy writable = " . is_writable($dummyDir) . "\n";
|
$text .= "Cache dummy writable = " . is_writable($dummyDir) . "\n";
|
||||||
|
$text .= "Cache srgb writable = " . is_writable($srgbDir) . "\n";
|
||||||
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
||||||
|
|
||||||
$no = extension_loaded('exif') ? null : 'NOT';
|
$no = extension_loaded('exif') ? null : 'NOT';
|
||||||
@@ -1002,6 +1045,9 @@ if ($status) {
|
|||||||
$no = extension_loaded('curl') ? null : 'NOT';
|
$no = extension_loaded('curl') ? null : 'NOT';
|
||||||
$text .= "Extension curl is $no loaded.<br>";
|
$text .= "Extension curl is $no loaded.<br>";
|
||||||
|
|
||||||
|
$no = extension_loaded('imagick') ? null : 'NOT';
|
||||||
|
$text .= "Extension imagick is $no loaded.<br>";
|
||||||
|
|
||||||
$no = extension_loaded('gd') ? null : 'NOT';
|
$no = extension_loaded('gd') ? null : 'NOT';
|
||||||
$text .= "Extension gd is $no loaded.<br>";
|
$text .= "Extension gd is $no loaded.<br>";
|
||||||
|
|
||||||
|
BIN
webroot/img/car_srgb.png
Normal file
BIN
webroot/img/car_srgb.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 245 KiB |
BIN
webroot/img/hamburger.jpg
Normal file
BIN
webroot/img/hamburger.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 517 KiB |
@@ -13,7 +13,8 @@ return array(
|
|||||||
* Default values:
|
* Default values:
|
||||||
* mode: 'production'
|
* mode: 'production'
|
||||||
*/
|
*/
|
||||||
//'mode' => 'production', // 'development', 'strict'
|
//'mode' => 'production', // 'development', 'strict'
|
||||||
|
//'mode' => 'development', // 'development', 'strict'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -121,6 +122,24 @@ return array(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the image to srgb before processing. Saves the converted
|
||||||
|
* image in the sub cache dir. This option is default false but can
|
||||||
|
* be changed to default true to do this conversion for all images.
|
||||||
|
* This option requires PHP extension imagick and will silently fail
|
||||||
|
* if that is not installed.
|
||||||
|
*
|
||||||
|
* Default value:
|
||||||
|
* srgb_dir: $cachePath/srgb
|
||||||
|
* srgb_default: false
|
||||||
|
* srgb_colorprofile: __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc'
|
||||||
|
*/
|
||||||
|
//'srgb_dir' => __DIR__ . '/../cache/srgb/',
|
||||||
|
//'srgb_default' => false,
|
||||||
|
//'srgb_colorprofile' => __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function (hook) can be called after img.php has processed all
|
* A function (hook) can be called after img.php has processed all
|
||||||
* configuration options and before processing the image using CImage.
|
* configuration options and before processing the image using CImage.
|
||||||
|
203
webroot/imgd.php
203
webroot/imgd.php
@@ -2217,10 +2217,11 @@ class CImage
|
|||||||
* @param string $base as optional basepath for storing file.
|
* @param string $base as optional basepath for storing file.
|
||||||
* @param boolean $useSubdir use or skip the subdir part when creating the
|
* @param boolean $useSubdir use or skip the subdir part when creating the
|
||||||
* filename.
|
* filename.
|
||||||
|
* @param string $prefix to add as part of filename
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function generateFilename($base = null, $useSubdir = true)
|
public function generateFilename($base = null, $useSubdir = true, $prefix = null)
|
||||||
{
|
{
|
||||||
$filename = basename($this->pathToImage);
|
$filename = basename($this->pathToImage);
|
||||||
$cropToFit = $this->cropToFit ? '_cf' : null;
|
$cropToFit = $this->cropToFit ? '_cf' : null;
|
||||||
@@ -2242,8 +2243,8 @@ class CImage
|
|||||||
$copyStrat = "_rs";
|
$copyStrat = "_rs";
|
||||||
}
|
}
|
||||||
|
|
||||||
$width = $this->newWidth;
|
$width = $this->newWidth ? '_' . $this->newWidth : null;
|
||||||
$height = $this->newHeight;
|
$height = $this->newHeight ? '_' . $this->newHeight : null;
|
||||||
|
|
||||||
$offset = isset($this->offset)
|
$offset = isset($this->offset)
|
||||||
? '_o' . $this->offset['top'] . '-' . $this->offset['right'] . '-' . $this->offset['bottom'] . '-' . $this->offset['left']
|
? '_o' . $this->offset['top'] . '-' . $this->offset['right'] . '-' . $this->offset['bottom'] . '-' . $this->offset['left']
|
||||||
@@ -2293,8 +2294,8 @@ class CImage
|
|||||||
$subdir .= '_';
|
$subdir .= '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $subdir . $filename . '_' . $width . '_'
|
$file = $prefix . $subdir . $filename . $width . $height
|
||||||
. $height . $offset . $crop . $cropToFit . $fillToFit
|
. $offset . $crop . $cropToFit . $fillToFit
|
||||||
. $crop_x . $crop_y . $upscale
|
. $crop_x . $crop_y . $upscale
|
||||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||||
. $optimize . $compress
|
. $optimize . $compress
|
||||||
@@ -3316,6 +3317,74 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert image from one colorpsace/color profile to sRGB without
|
||||||
|
* color profile.
|
||||||
|
*
|
||||||
|
* @param string $src of image.
|
||||||
|
* @param string $dir as base directory where images are.
|
||||||
|
* @param string $cache as base directory where to store images.
|
||||||
|
* @param string $iccFile filename of colorprofile.
|
||||||
|
* @param boolean $useCache or not, default to always use cache.
|
||||||
|
*
|
||||||
|
* @return string | boolean false if no conversion else the converted
|
||||||
|
* filename.
|
||||||
|
*/
|
||||||
|
public function convert2sRGBColorSpace($src, $dir, $cache, $iccFile, $useCache = true)
|
||||||
|
{
|
||||||
|
if ($this->verbose) {
|
||||||
|
$this->log("# Converting image to sRGB colorspace.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists("Imagick")) {
|
||||||
|
$this->log(" Ignoring since Imagemagick is not installed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare
|
||||||
|
$this->setSaveFolder($cache)
|
||||||
|
->setSource($src, $dir)
|
||||||
|
->generateFilename(null, false, 'srgb_');
|
||||||
|
|
||||||
|
// Check if the cached version is accurate.
|
||||||
|
if ($useCache && is_readable($this->cacheFileName)) {
|
||||||
|
$fileTime = filemtime($this->pathToImage);
|
||||||
|
$cacheTime = filemtime($this->cacheFileName);
|
||||||
|
|
||||||
|
if ($fileTime <= $cacheTime) {
|
||||||
|
$this->log(" Using cached version: " . $this->cacheFileName);
|
||||||
|
return $this->cacheFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only covert if cachedir is writable
|
||||||
|
if (is_writable($this->saveFolder)) {
|
||||||
|
// Load file and check if conversion is needed
|
||||||
|
$image = new Imagick($this->pathToImage);
|
||||||
|
$colorspace = $image->getImageColorspace();
|
||||||
|
$this->log(" Current colorspace: " . $colorspace);
|
||||||
|
|
||||||
|
$profiles = $image->getImageProfiles('*', false);
|
||||||
|
$hasICCProfile = (array_search('icc', $profiles) !== false);
|
||||||
|
$this->log(" Has ICC color profile: " . ($hasICCProfile ? "YES" : "NO"));
|
||||||
|
|
||||||
|
if ($colorspace != Imagick::COLORSPACE_SRGB || $hasICCProfile) {
|
||||||
|
$this->log(" Converting to sRGB.");
|
||||||
|
|
||||||
|
$sRGBicc = file_get_contents($iccFile);
|
||||||
|
$image->profileImage('icc', $sRGBicc);
|
||||||
|
|
||||||
|
$image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
|
||||||
|
$image->writeImage($this->cacheFileName);
|
||||||
|
return $this->cacheFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a hard link, as an alias, to the cached file.
|
* Create a hard link, as an alias, to the cached file.
|
||||||
*
|
*
|
||||||
@@ -3634,7 +3703,7 @@ EOD;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$version = "v0.7.7 (2015-10-21)";
|
$version = "v0.7.8 (2015-12-06)";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3642,21 +3711,33 @@ $version = "v0.7.7 (2015-10-21)";
|
|||||||
* Display error message.
|
* Display error message.
|
||||||
*
|
*
|
||||||
* @param string $msg to display.
|
* @param string $msg to display.
|
||||||
|
* @param int $type of HTTP error to display.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function errorPage($msg)
|
function errorPage($msg, $type = 500)
|
||||||
{
|
{
|
||||||
global $mode;
|
global $mode;
|
||||||
|
|
||||||
header("HTTP/1.0 500 Internal Server Error");
|
switch ($type) {
|
||||||
|
case 403:
|
||||||
|
$header = "403 Forbidden";
|
||||||
|
break;
|
||||||
|
case 404:
|
||||||
|
$header = "404 Not Found";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$header = "500 Internal Server Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
header("HTTP/1.0 $header");
|
||||||
|
|
||||||
if ($mode == 'development') {
|
if ($mode == 'development') {
|
||||||
die("[img.php] $msg");
|
die("[img.php] $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log("[img.php] $msg");
|
error_log("[img.php] $msg");
|
||||||
die("HTTP/1.0 500 Internal Server Error");
|
die("HTTP/1.0 $header");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3671,7 +3752,7 @@ set_exception_handler(function ($exception) {
|
|||||||
. "</p><pre>"
|
. "</p><pre>"
|
||||||
. $exception->getTraceAsString()
|
. $exception->getTraceAsString()
|
||||||
. "</pre>"
|
. "</pre>"
|
||||||
);
|
, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -3801,7 +3882,7 @@ set_time_limit(20);
|
|||||||
ini_set('gd.jpeg_ignore_warning', 1);
|
ini_set('gd.jpeg_ignore_warning', 1);
|
||||||
|
|
||||||
if (!extension_loaded('gd')) {
|
if (!extension_loaded('gd')) {
|
||||||
errorPage("Extension gd is nod loaded.");
|
errorPage("Extension gd is not loaded.", 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specific settings for each mode
|
// Specific settings for each mode
|
||||||
@@ -3813,7 +3894,7 @@ if ($mode == 'strict') {
|
|||||||
$verbose = false;
|
$verbose = false;
|
||||||
$status = false;
|
$status = false;
|
||||||
$verboseFile = false;
|
$verboseFile = false;
|
||||||
|
|
||||||
} elseif ($mode == 'production') {
|
} elseif ($mode == 'production') {
|
||||||
|
|
||||||
error_reporting(-1);
|
error_reporting(-1);
|
||||||
@@ -3837,7 +3918,7 @@ if ($mode == 'strict') {
|
|||||||
ini_set('log_errors', 0);
|
ini_set('log_errors', 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
errorPage("Unknown mode: $mode");
|
errorPage("Unknown mode: $mode", 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("mode = $mode");
|
verbose("mode = $mode");
|
||||||
@@ -3886,7 +3967,7 @@ if ($pwd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($pwdAlways && $passwordMatch !== true) {
|
if ($pwdAlways && $passwordMatch !== true) {
|
||||||
errorPage("Password required and does not match or exists.");
|
errorPage("Password required and does not match or exists.", 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("password match = $passwordMatch");
|
verbose("password match = $passwordMatch");
|
||||||
@@ -3910,9 +3991,9 @@ if (!$allowHotlinking) {
|
|||||||
; // Always allow when password match
|
; // Always allow when password match
|
||||||
verbose("Hotlinking since passwordmatch");
|
verbose("Hotlinking since passwordmatch");
|
||||||
} elseif ($passwordMatch === false) {
|
} elseif ($passwordMatch === false) {
|
||||||
errorPage("Hotlinking/leeching not allowed when password missmatch.");
|
errorPage("Hotlinking/leeching not allowed when password missmatch.", 403);
|
||||||
} elseif (!$referer) {
|
} elseif (!$referer) {
|
||||||
errorPage("Hotlinking/leeching not allowed and referer is missing.");
|
errorPage("Hotlinking/leeching not allowed and referer is missing.", 403);
|
||||||
} elseif (strcmp($serverName, $refererHost) == 0) {
|
} elseif (strcmp($serverName, $refererHost) == 0) {
|
||||||
; // Allow when serverName matches refererHost
|
; // Allow when serverName matches refererHost
|
||||||
verbose("Hotlinking disallowed but serverName matches refererHost.");
|
verbose("Hotlinking disallowed but serverName matches refererHost.");
|
||||||
@@ -3923,11 +4004,11 @@ if (!$allowHotlinking) {
|
|||||||
if ($allowedByWhitelist) {
|
if ($allowedByWhitelist) {
|
||||||
verbose("Hotlinking/leeching allowed by whitelist.");
|
verbose("Hotlinking/leeching allowed by whitelist.");
|
||||||
} else {
|
} else {
|
||||||
errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.");
|
errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
errorPage("Hotlinking/leeching not allowed.");
|
errorPage("Hotlinking/leeching not allowed.", 403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4001,7 +4082,7 @@ if (isset($shortcut)
|
|||||||
* src - the source image file.
|
* src - the source image file.
|
||||||
*/
|
*/
|
||||||
$srcImage = urldecode(get('src'))
|
$srcImage = urldecode(get('src'))
|
||||||
or errorPage('Must set src-attribute.');
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
// Check for valid/invalid characters
|
// Check for valid/invalid characters
|
||||||
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
||||||
@@ -4014,7 +4095,7 @@ $dummyFilename = getConfig('dummy_filename', 'dummy');
|
|||||||
$dummyImage = false;
|
$dummyImage = false;
|
||||||
|
|
||||||
preg_match($validFilename, $srcImage)
|
preg_match($validFilename, $srcImage)
|
||||||
or errorPage('Filename contains invalid characters.');
|
or errorPage('Filename contains invalid characters.', 404);
|
||||||
|
|
||||||
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||||
|
|
||||||
@@ -4035,13 +4116,13 @@ if ($dummyEnabled && $srcImage === $dummyFilename) {
|
|||||||
or errorPage(
|
or errorPage(
|
||||||
'Source image is not a valid file, check the filename and that a
|
'Source image is not a valid file, check the filename and that a
|
||||||
matching file exists on the filesystem.'
|
matching file exists on the filesystem.'
|
||||||
);
|
, 404);
|
||||||
|
|
||||||
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
||||||
or errorPage(
|
or errorPage(
|
||||||
'Security constraint: Source image is not below the directory "image_path"
|
'Security constraint: Source image is not below the directory "image_path"
|
||||||
as specified in the config file img_config.php.'
|
as specified in the config file img_config.php.'
|
||||||
);
|
, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("src = $srcImage");
|
verbose("src = $srcImage");
|
||||||
@@ -4090,11 +4171,11 @@ if (isset($sizes[$newWidth])) {
|
|||||||
// Support width as % of original width
|
// Support width as % of original width
|
||||||
if ($newWidth[strlen($newWidth)-1] == '%') {
|
if ($newWidth[strlen($newWidth)-1] == '%') {
|
||||||
is_numeric(substr($newWidth, 0, -1))
|
is_numeric(substr($newWidth, 0, -1))
|
||||||
or errorPage('Width % not numeric.');
|
or errorPage('Width % not numeric.', 404);
|
||||||
} else {
|
} else {
|
||||||
is_null($newWidth)
|
is_null($newWidth)
|
||||||
or ($newWidth > 10 && $newWidth <= $maxWidth)
|
or ($newWidth > 10 && $newWidth <= $maxWidth)
|
||||||
or errorPage('Width out of range.');
|
or errorPage('Width out of range.', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("new width = $newWidth");
|
verbose("new width = $newWidth");
|
||||||
@@ -4115,11 +4196,11 @@ if (isset($sizes[$newHeight])) {
|
|||||||
// height
|
// height
|
||||||
if ($newHeight[strlen($newHeight)-1] == '%') {
|
if ($newHeight[strlen($newHeight)-1] == '%') {
|
||||||
is_numeric(substr($newHeight, 0, -1))
|
is_numeric(substr($newHeight, 0, -1))
|
||||||
or errorPage('Height % out of range.');
|
or errorPage('Height % out of range.', 404);
|
||||||
} else {
|
} else {
|
||||||
is_null($newHeight)
|
is_null($newHeight)
|
||||||
or ($newHeight > 10 && $newHeight <= $maxHeight)
|
or ($newHeight > 10 && $newHeight <= $maxHeight)
|
||||||
or errorPage('Hight out of range.');
|
or errorPage('Height out of range.', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("new height = $newHeight");
|
verbose("new height = $newHeight");
|
||||||
@@ -4157,7 +4238,7 @@ if ($negateAspectRatio) {
|
|||||||
|
|
||||||
is_null($aspectRatio)
|
is_null($aspectRatio)
|
||||||
or is_numeric($aspectRatio)
|
or is_numeric($aspectRatio)
|
||||||
or errorPage('Aspect ratio out of range');
|
or errorPage('Aspect ratio out of range', 404);
|
||||||
|
|
||||||
verbose("aspect ratio = $aspectRatio");
|
verbose("aspect ratio = $aspectRatio");
|
||||||
|
|
||||||
@@ -4257,6 +4338,12 @@ verbose("area = $area");
|
|||||||
* skip-original, so - skip the original image and always process a new image
|
* skip-original, so - skip the original image and always process a new image
|
||||||
*/
|
*/
|
||||||
$useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
$useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
||||||
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
|
if ($useOriginalDefault === true) {
|
||||||
|
verbose("use original is default ON");
|
||||||
|
$useOriginal = true;
|
||||||
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
|
||||||
@@ -4279,7 +4366,7 @@ $qualityDefault = getConfig('jpg_quality', null);
|
|||||||
|
|
||||||
is_null($quality)
|
is_null($quality)
|
||||||
or ($quality > 0 and $quality <= 100)
|
or ($quality > 0 and $quality <= 100)
|
||||||
or errorPage('Quality out of range');
|
or errorPage('Quality out of range', 404);
|
||||||
|
|
||||||
if (is_null($quality) && !is_null($qualityDefault)) {
|
if (is_null($quality) && !is_null($qualityDefault)) {
|
||||||
$quality = $qualityDefault;
|
$quality = $qualityDefault;
|
||||||
@@ -4297,7 +4384,7 @@ $compressDefault = getConfig('png_compression', null);
|
|||||||
|
|
||||||
is_null($compress)
|
is_null($compress)
|
||||||
or ($compress > 0 and $compress <= 9)
|
or ($compress > 0 and $compress <= 9)
|
||||||
or errorPage('Compress out of range');
|
or errorPage('Compress out of range', 404);
|
||||||
|
|
||||||
if (is_null($compress) && !is_null($compressDefault)) {
|
if (is_null($compress) && !is_null($compressDefault)) {
|
||||||
$compress = $compressDefault;
|
$compress = $compressDefault;
|
||||||
@@ -4323,7 +4410,7 @@ $scale = get(array('scale', 's'));
|
|||||||
|
|
||||||
is_null($scale)
|
is_null($scale)
|
||||||
or ($scale >= 0 and $scale <= 400)
|
or ($scale >= 0 and $scale <= 400)
|
||||||
or errorPage('Scale out of range');
|
or errorPage('Scale out of range', 404);
|
||||||
|
|
||||||
verbose("scale = $scale");
|
verbose("scale = $scale");
|
||||||
|
|
||||||
@@ -4372,7 +4459,7 @@ $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb'));
|
|||||||
|
|
||||||
is_null($rotateBefore)
|
is_null($rotateBefore)
|
||||||
or ($rotateBefore >= -360 and $rotateBefore <= 360)
|
or ($rotateBefore >= -360 and $rotateBefore <= 360)
|
||||||
or errorPage('RotateBefore out of range');
|
or errorPage('RotateBefore out of range', 404);
|
||||||
|
|
||||||
verbose("rotateBefore = $rotateBefore");
|
verbose("rotateBefore = $rotateBefore");
|
||||||
|
|
||||||
@@ -4385,7 +4472,7 @@ $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r'));
|
|||||||
|
|
||||||
is_null($rotateAfter)
|
is_null($rotateAfter)
|
||||||
or ($rotateAfter >= -360 and $rotateAfter <= 360)
|
or ($rotateAfter >= -360 and $rotateAfter <= 360)
|
||||||
or errorPage('RotateBefore out of range');
|
or errorPage('RotateBefore out of range', 404);
|
||||||
|
|
||||||
verbose("rotateAfter = $rotateAfter");
|
verbose("rotateAfter = $rotateAfter");
|
||||||
|
|
||||||
@@ -4534,13 +4621,13 @@ if ($alias && $aliasPath && $passwordMatch) {
|
|||||||
$useCache = false;
|
$useCache = false;
|
||||||
|
|
||||||
is_writable($aliasPath)
|
is_writable($aliasPath)
|
||||||
or errorPage("Directory for alias is not writable.");
|
or errorPage("Directory for alias is not writable.", 403);
|
||||||
|
|
||||||
preg_match($validAliasname, $alias)
|
preg_match($validAliasname, $alias)
|
||||||
or errorPage('Filename for alias contains invalid characters. Do not add extension.');
|
or errorPage('Filename for alias contains invalid characters. Do not add extension.', 404);
|
||||||
|
|
||||||
} elseif ($alias) {
|
} elseif ($alias) {
|
||||||
errorPage('Alias is not enabled in the config file or password not matching.');
|
errorPage('Alias is not enabled in the config file or password not matching.', 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("alias = $alias");
|
verbose("alias = $alias");
|
||||||
@@ -4592,12 +4679,48 @@ if ($dummyImage === true) {
|
|||||||
|
|
||||||
$srcImage = $img->getTarget();
|
$srcImage = $img->getTarget();
|
||||||
$imagePath = null;
|
$imagePath = null;
|
||||||
|
|
||||||
verbose("src (updated) = $srcImage");
|
verbose("src (updated) = $srcImage");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare a sRGB version of the image and use it as source image.
|
||||||
|
*/
|
||||||
|
$srgbDirName = "/srgb";
|
||||||
|
$srgbDir = realpath(getConfig('srgb_dir', $cachePath . $srgbDirName));
|
||||||
|
$srgbDefault = getConfig('srgb_default', false);
|
||||||
|
$srgbColorProfile = getConfig('srgb_colorprofile', __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc');
|
||||||
|
$srgb = getDefined('srgb', true, null);
|
||||||
|
|
||||||
|
if ($srgb || $srgbDefault) {
|
||||||
|
|
||||||
|
if (!is_writable($srgbDir)) {
|
||||||
|
if (is_writable($cachePath)) {
|
||||||
|
mkdir($srgbDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = $img->convert2sRGBColorSpace(
|
||||||
|
$srcImage,
|
||||||
|
$imagePath,
|
||||||
|
$srgbDir,
|
||||||
|
$srgbColorProfile,
|
||||||
|
$useCache
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($filename) {
|
||||||
|
$srcImage = $img->getTarget();
|
||||||
|
$imagePath = null;
|
||||||
|
verbose("srgb conversion and saved to cache = $srcImage");
|
||||||
|
} else {
|
||||||
|
verbose("srgb not op");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display status
|
* Display status
|
||||||
*/
|
*/
|
||||||
@@ -4608,6 +4731,7 @@ if ($status) {
|
|||||||
$text .= "Allow remote images = $allowRemote\n";
|
$text .= "Allow remote images = $allowRemote\n";
|
||||||
$text .= "Cache writable = " . is_writable($cachePath) . "\n";
|
$text .= "Cache writable = " . is_writable($cachePath) . "\n";
|
||||||
$text .= "Cache dummy writable = " . is_writable($dummyDir) . "\n";
|
$text .= "Cache dummy writable = " . is_writable($dummyDir) . "\n";
|
||||||
|
$text .= "Cache srgb writable = " . is_writable($srgbDir) . "\n";
|
||||||
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
||||||
|
|
||||||
$no = extension_loaded('exif') ? null : 'NOT';
|
$no = extension_loaded('exif') ? null : 'NOT';
|
||||||
@@ -4616,6 +4740,9 @@ if ($status) {
|
|||||||
$no = extension_loaded('curl') ? null : 'NOT';
|
$no = extension_loaded('curl') ? null : 'NOT';
|
||||||
$text .= "Extension curl is $no loaded.<br>";
|
$text .= "Extension curl is $no loaded.<br>";
|
||||||
|
|
||||||
|
$no = extension_loaded('imagick') ? null : 'NOT';
|
||||||
|
$text .= "Extension imagick is $no loaded.<br>";
|
||||||
|
|
||||||
$no = extension_loaded('gd') ? null : 'NOT';
|
$no = extension_loaded('gd') ? null : 'NOT';
|
||||||
$text .= "Extension gd is $no loaded.<br>";
|
$text .= "Extension gd is $no loaded.<br>";
|
||||||
|
|
||||||
@@ -4651,7 +4778,7 @@ $hookBeforeCImage = getConfig('hook_before_CImage', null);
|
|||||||
|
|
||||||
if (is_callable($hookBeforeCImage)) {
|
if (is_callable($hookBeforeCImage)) {
|
||||||
verbose("hookBeforeCImage activated");
|
verbose("hookBeforeCImage activated");
|
||||||
|
|
||||||
$allConfig = $hookBeforeCImage($img, array(
|
$allConfig = $hookBeforeCImage($img, array(
|
||||||
// Options for calculate dimensions
|
// Options for calculate dimensions
|
||||||
'newWidth' => $newWidth,
|
'newWidth' => $newWidth,
|
||||||
@@ -4684,7 +4811,7 @@ if (is_callable($hookBeforeCImage)) {
|
|||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => $outputFormat,
|
'outputFormat' => $outputFormat,
|
||||||
'dpr' => $dpr,
|
'dpr' => $dpr,
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
'postProcessing' => $postProcessing,
|
'postProcessing' => $postProcessing,
|
||||||
));
|
));
|
||||||
|
203
webroot/imgp.php
203
webroot/imgp.php
@@ -2217,10 +2217,11 @@ class CImage
|
|||||||
* @param string $base as optional basepath for storing file.
|
* @param string $base as optional basepath for storing file.
|
||||||
* @param boolean $useSubdir use or skip the subdir part when creating the
|
* @param boolean $useSubdir use or skip the subdir part when creating the
|
||||||
* filename.
|
* filename.
|
||||||
|
* @param string $prefix to add as part of filename
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function generateFilename($base = null, $useSubdir = true)
|
public function generateFilename($base = null, $useSubdir = true, $prefix = null)
|
||||||
{
|
{
|
||||||
$filename = basename($this->pathToImage);
|
$filename = basename($this->pathToImage);
|
||||||
$cropToFit = $this->cropToFit ? '_cf' : null;
|
$cropToFit = $this->cropToFit ? '_cf' : null;
|
||||||
@@ -2242,8 +2243,8 @@ class CImage
|
|||||||
$copyStrat = "_rs";
|
$copyStrat = "_rs";
|
||||||
}
|
}
|
||||||
|
|
||||||
$width = $this->newWidth;
|
$width = $this->newWidth ? '_' . $this->newWidth : null;
|
||||||
$height = $this->newHeight;
|
$height = $this->newHeight ? '_' . $this->newHeight : null;
|
||||||
|
|
||||||
$offset = isset($this->offset)
|
$offset = isset($this->offset)
|
||||||
? '_o' . $this->offset['top'] . '-' . $this->offset['right'] . '-' . $this->offset['bottom'] . '-' . $this->offset['left']
|
? '_o' . $this->offset['top'] . '-' . $this->offset['right'] . '-' . $this->offset['bottom'] . '-' . $this->offset['left']
|
||||||
@@ -2293,8 +2294,8 @@ class CImage
|
|||||||
$subdir .= '_';
|
$subdir .= '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
$file = $subdir . $filename . '_' . $width . '_'
|
$file = $prefix . $subdir . $filename . $width . $height
|
||||||
. $height . $offset . $crop . $cropToFit . $fillToFit
|
. $offset . $crop . $cropToFit . $fillToFit
|
||||||
. $crop_x . $crop_y . $upscale
|
. $crop_x . $crop_y . $upscale
|
||||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||||
. $optimize . $compress
|
. $optimize . $compress
|
||||||
@@ -3316,6 +3317,74 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert image from one colorpsace/color profile to sRGB without
|
||||||
|
* color profile.
|
||||||
|
*
|
||||||
|
* @param string $src of image.
|
||||||
|
* @param string $dir as base directory where images are.
|
||||||
|
* @param string $cache as base directory where to store images.
|
||||||
|
* @param string $iccFile filename of colorprofile.
|
||||||
|
* @param boolean $useCache or not, default to always use cache.
|
||||||
|
*
|
||||||
|
* @return string | boolean false if no conversion else the converted
|
||||||
|
* filename.
|
||||||
|
*/
|
||||||
|
public function convert2sRGBColorSpace($src, $dir, $cache, $iccFile, $useCache = true)
|
||||||
|
{
|
||||||
|
if ($this->verbose) {
|
||||||
|
$this->log("# Converting image to sRGB colorspace.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists("Imagick")) {
|
||||||
|
$this->log(" Ignoring since Imagemagick is not installed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare
|
||||||
|
$this->setSaveFolder($cache)
|
||||||
|
->setSource($src, $dir)
|
||||||
|
->generateFilename(null, false, 'srgb_');
|
||||||
|
|
||||||
|
// Check if the cached version is accurate.
|
||||||
|
if ($useCache && is_readable($this->cacheFileName)) {
|
||||||
|
$fileTime = filemtime($this->pathToImage);
|
||||||
|
$cacheTime = filemtime($this->cacheFileName);
|
||||||
|
|
||||||
|
if ($fileTime <= $cacheTime) {
|
||||||
|
$this->log(" Using cached version: " . $this->cacheFileName);
|
||||||
|
return $this->cacheFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only covert if cachedir is writable
|
||||||
|
if (is_writable($this->saveFolder)) {
|
||||||
|
// Load file and check if conversion is needed
|
||||||
|
$image = new Imagick($this->pathToImage);
|
||||||
|
$colorspace = $image->getImageColorspace();
|
||||||
|
$this->log(" Current colorspace: " . $colorspace);
|
||||||
|
|
||||||
|
$profiles = $image->getImageProfiles('*', false);
|
||||||
|
$hasICCProfile = (array_search('icc', $profiles) !== false);
|
||||||
|
$this->log(" Has ICC color profile: " . ($hasICCProfile ? "YES" : "NO"));
|
||||||
|
|
||||||
|
if ($colorspace != Imagick::COLORSPACE_SRGB || $hasICCProfile) {
|
||||||
|
$this->log(" Converting to sRGB.");
|
||||||
|
|
||||||
|
$sRGBicc = file_get_contents($iccFile);
|
||||||
|
$image->profileImage('icc', $sRGBicc);
|
||||||
|
|
||||||
|
$image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
|
||||||
|
$image->writeImage($this->cacheFileName);
|
||||||
|
return $this->cacheFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a hard link, as an alias, to the cached file.
|
* Create a hard link, as an alias, to the cached file.
|
||||||
*
|
*
|
||||||
@@ -3634,7 +3703,7 @@ EOD;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$version = "v0.7.7 (2015-10-21)";
|
$version = "v0.7.8 (2015-12-06)";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3642,21 +3711,33 @@ $version = "v0.7.7 (2015-10-21)";
|
|||||||
* Display error message.
|
* Display error message.
|
||||||
*
|
*
|
||||||
* @param string $msg to display.
|
* @param string $msg to display.
|
||||||
|
* @param int $type of HTTP error to display.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function errorPage($msg)
|
function errorPage($msg, $type = 500)
|
||||||
{
|
{
|
||||||
global $mode;
|
global $mode;
|
||||||
|
|
||||||
header("HTTP/1.0 500 Internal Server Error");
|
switch ($type) {
|
||||||
|
case 403:
|
||||||
|
$header = "403 Forbidden";
|
||||||
|
break;
|
||||||
|
case 404:
|
||||||
|
$header = "404 Not Found";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$header = "500 Internal Server Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
header("HTTP/1.0 $header");
|
||||||
|
|
||||||
if ($mode == 'development') {
|
if ($mode == 'development') {
|
||||||
die("[img.php] $msg");
|
die("[img.php] $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log("[img.php] $msg");
|
error_log("[img.php] $msg");
|
||||||
die("HTTP/1.0 500 Internal Server Error");
|
die("HTTP/1.0 $header");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3671,7 +3752,7 @@ set_exception_handler(function ($exception) {
|
|||||||
. "</p><pre>"
|
. "</p><pre>"
|
||||||
. $exception->getTraceAsString()
|
. $exception->getTraceAsString()
|
||||||
. "</pre>"
|
. "</pre>"
|
||||||
);
|
, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -3801,7 +3882,7 @@ set_time_limit(20);
|
|||||||
ini_set('gd.jpeg_ignore_warning', 1);
|
ini_set('gd.jpeg_ignore_warning', 1);
|
||||||
|
|
||||||
if (!extension_loaded('gd')) {
|
if (!extension_loaded('gd')) {
|
||||||
errorPage("Extension gd is nod loaded.");
|
errorPage("Extension gd is not loaded.", 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specific settings for each mode
|
// Specific settings for each mode
|
||||||
@@ -3813,7 +3894,7 @@ if ($mode == 'strict') {
|
|||||||
$verbose = false;
|
$verbose = false;
|
||||||
$status = false;
|
$status = false;
|
||||||
$verboseFile = false;
|
$verboseFile = false;
|
||||||
|
|
||||||
} elseif ($mode == 'production') {
|
} elseif ($mode == 'production') {
|
||||||
|
|
||||||
error_reporting(-1);
|
error_reporting(-1);
|
||||||
@@ -3837,7 +3918,7 @@ if ($mode == 'strict') {
|
|||||||
ini_set('log_errors', 0);
|
ini_set('log_errors', 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
errorPage("Unknown mode: $mode");
|
errorPage("Unknown mode: $mode", 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("mode = $mode");
|
verbose("mode = $mode");
|
||||||
@@ -3886,7 +3967,7 @@ if ($pwd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($pwdAlways && $passwordMatch !== true) {
|
if ($pwdAlways && $passwordMatch !== true) {
|
||||||
errorPage("Password required and does not match or exists.");
|
errorPage("Password required and does not match or exists.", 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("password match = $passwordMatch");
|
verbose("password match = $passwordMatch");
|
||||||
@@ -3910,9 +3991,9 @@ if (!$allowHotlinking) {
|
|||||||
; // Always allow when password match
|
; // Always allow when password match
|
||||||
verbose("Hotlinking since passwordmatch");
|
verbose("Hotlinking since passwordmatch");
|
||||||
} elseif ($passwordMatch === false) {
|
} elseif ($passwordMatch === false) {
|
||||||
errorPage("Hotlinking/leeching not allowed when password missmatch.");
|
errorPage("Hotlinking/leeching not allowed when password missmatch.", 403);
|
||||||
} elseif (!$referer) {
|
} elseif (!$referer) {
|
||||||
errorPage("Hotlinking/leeching not allowed and referer is missing.");
|
errorPage("Hotlinking/leeching not allowed and referer is missing.", 403);
|
||||||
} elseif (strcmp($serverName, $refererHost) == 0) {
|
} elseif (strcmp($serverName, $refererHost) == 0) {
|
||||||
; // Allow when serverName matches refererHost
|
; // Allow when serverName matches refererHost
|
||||||
verbose("Hotlinking disallowed but serverName matches refererHost.");
|
verbose("Hotlinking disallowed but serverName matches refererHost.");
|
||||||
@@ -3923,11 +4004,11 @@ if (!$allowHotlinking) {
|
|||||||
if ($allowedByWhitelist) {
|
if ($allowedByWhitelist) {
|
||||||
verbose("Hotlinking/leeching allowed by whitelist.");
|
verbose("Hotlinking/leeching allowed by whitelist.");
|
||||||
} else {
|
} else {
|
||||||
errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.");
|
errorPage("Hotlinking/leeching not allowed by whitelist. Referer: $referer.", 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
errorPage("Hotlinking/leeching not allowed.");
|
errorPage("Hotlinking/leeching not allowed.", 403);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4001,7 +4082,7 @@ if (isset($shortcut)
|
|||||||
* src - the source image file.
|
* src - the source image file.
|
||||||
*/
|
*/
|
||||||
$srcImage = urldecode(get('src'))
|
$srcImage = urldecode(get('src'))
|
||||||
or errorPage('Must set src-attribute.');
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
// Check for valid/invalid characters
|
// Check for valid/invalid characters
|
||||||
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
||||||
@@ -4014,7 +4095,7 @@ $dummyFilename = getConfig('dummy_filename', 'dummy');
|
|||||||
$dummyImage = false;
|
$dummyImage = false;
|
||||||
|
|
||||||
preg_match($validFilename, $srcImage)
|
preg_match($validFilename, $srcImage)
|
||||||
or errorPage('Filename contains invalid characters.');
|
or errorPage('Filename contains invalid characters.', 404);
|
||||||
|
|
||||||
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||||
|
|
||||||
@@ -4035,13 +4116,13 @@ if ($dummyEnabled && $srcImage === $dummyFilename) {
|
|||||||
or errorPage(
|
or errorPage(
|
||||||
'Source image is not a valid file, check the filename and that a
|
'Source image is not a valid file, check the filename and that a
|
||||||
matching file exists on the filesystem.'
|
matching file exists on the filesystem.'
|
||||||
);
|
, 404);
|
||||||
|
|
||||||
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
||||||
or errorPage(
|
or errorPage(
|
||||||
'Security constraint: Source image is not below the directory "image_path"
|
'Security constraint: Source image is not below the directory "image_path"
|
||||||
as specified in the config file img_config.php.'
|
as specified in the config file img_config.php.'
|
||||||
);
|
, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("src = $srcImage");
|
verbose("src = $srcImage");
|
||||||
@@ -4090,11 +4171,11 @@ if (isset($sizes[$newWidth])) {
|
|||||||
// Support width as % of original width
|
// Support width as % of original width
|
||||||
if ($newWidth[strlen($newWidth)-1] == '%') {
|
if ($newWidth[strlen($newWidth)-1] == '%') {
|
||||||
is_numeric(substr($newWidth, 0, -1))
|
is_numeric(substr($newWidth, 0, -1))
|
||||||
or errorPage('Width % not numeric.');
|
or errorPage('Width % not numeric.', 404);
|
||||||
} else {
|
} else {
|
||||||
is_null($newWidth)
|
is_null($newWidth)
|
||||||
or ($newWidth > 10 && $newWidth <= $maxWidth)
|
or ($newWidth > 10 && $newWidth <= $maxWidth)
|
||||||
or errorPage('Width out of range.');
|
or errorPage('Width out of range.', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("new width = $newWidth");
|
verbose("new width = $newWidth");
|
||||||
@@ -4115,11 +4196,11 @@ if (isset($sizes[$newHeight])) {
|
|||||||
// height
|
// height
|
||||||
if ($newHeight[strlen($newHeight)-1] == '%') {
|
if ($newHeight[strlen($newHeight)-1] == '%') {
|
||||||
is_numeric(substr($newHeight, 0, -1))
|
is_numeric(substr($newHeight, 0, -1))
|
||||||
or errorPage('Height % out of range.');
|
or errorPage('Height % out of range.', 404);
|
||||||
} else {
|
} else {
|
||||||
is_null($newHeight)
|
is_null($newHeight)
|
||||||
or ($newHeight > 10 && $newHeight <= $maxHeight)
|
or ($newHeight > 10 && $newHeight <= $maxHeight)
|
||||||
or errorPage('Hight out of range.');
|
or errorPage('Height out of range.', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("new height = $newHeight");
|
verbose("new height = $newHeight");
|
||||||
@@ -4157,7 +4238,7 @@ if ($negateAspectRatio) {
|
|||||||
|
|
||||||
is_null($aspectRatio)
|
is_null($aspectRatio)
|
||||||
or is_numeric($aspectRatio)
|
or is_numeric($aspectRatio)
|
||||||
or errorPage('Aspect ratio out of range');
|
or errorPage('Aspect ratio out of range', 404);
|
||||||
|
|
||||||
verbose("aspect ratio = $aspectRatio");
|
verbose("aspect ratio = $aspectRatio");
|
||||||
|
|
||||||
@@ -4257,6 +4338,12 @@ verbose("area = $area");
|
|||||||
* skip-original, so - skip the original image and always process a new image
|
* skip-original, so - skip the original image and always process a new image
|
||||||
*/
|
*/
|
||||||
$useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
$useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
||||||
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
|
if ($useOriginalDefault === true) {
|
||||||
|
verbose("use original is default ON");
|
||||||
|
$useOriginal = true;
|
||||||
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
|
||||||
@@ -4279,7 +4366,7 @@ $qualityDefault = getConfig('jpg_quality', null);
|
|||||||
|
|
||||||
is_null($quality)
|
is_null($quality)
|
||||||
or ($quality > 0 and $quality <= 100)
|
or ($quality > 0 and $quality <= 100)
|
||||||
or errorPage('Quality out of range');
|
or errorPage('Quality out of range', 404);
|
||||||
|
|
||||||
if (is_null($quality) && !is_null($qualityDefault)) {
|
if (is_null($quality) && !is_null($qualityDefault)) {
|
||||||
$quality = $qualityDefault;
|
$quality = $qualityDefault;
|
||||||
@@ -4297,7 +4384,7 @@ $compressDefault = getConfig('png_compression', null);
|
|||||||
|
|
||||||
is_null($compress)
|
is_null($compress)
|
||||||
or ($compress > 0 and $compress <= 9)
|
or ($compress > 0 and $compress <= 9)
|
||||||
or errorPage('Compress out of range');
|
or errorPage('Compress out of range', 404);
|
||||||
|
|
||||||
if (is_null($compress) && !is_null($compressDefault)) {
|
if (is_null($compress) && !is_null($compressDefault)) {
|
||||||
$compress = $compressDefault;
|
$compress = $compressDefault;
|
||||||
@@ -4323,7 +4410,7 @@ $scale = get(array('scale', 's'));
|
|||||||
|
|
||||||
is_null($scale)
|
is_null($scale)
|
||||||
or ($scale >= 0 and $scale <= 400)
|
or ($scale >= 0 and $scale <= 400)
|
||||||
or errorPage('Scale out of range');
|
or errorPage('Scale out of range', 404);
|
||||||
|
|
||||||
verbose("scale = $scale");
|
verbose("scale = $scale");
|
||||||
|
|
||||||
@@ -4372,7 +4459,7 @@ $rotateBefore = get(array('rotateBefore', 'rotate-before', 'rb'));
|
|||||||
|
|
||||||
is_null($rotateBefore)
|
is_null($rotateBefore)
|
||||||
or ($rotateBefore >= -360 and $rotateBefore <= 360)
|
or ($rotateBefore >= -360 and $rotateBefore <= 360)
|
||||||
or errorPage('RotateBefore out of range');
|
or errorPage('RotateBefore out of range', 404);
|
||||||
|
|
||||||
verbose("rotateBefore = $rotateBefore");
|
verbose("rotateBefore = $rotateBefore");
|
||||||
|
|
||||||
@@ -4385,7 +4472,7 @@ $rotateAfter = get(array('rotateAfter', 'rotate-after', 'ra', 'rotate', 'r'));
|
|||||||
|
|
||||||
is_null($rotateAfter)
|
is_null($rotateAfter)
|
||||||
or ($rotateAfter >= -360 and $rotateAfter <= 360)
|
or ($rotateAfter >= -360 and $rotateAfter <= 360)
|
||||||
or errorPage('RotateBefore out of range');
|
or errorPage('RotateBefore out of range', 404);
|
||||||
|
|
||||||
verbose("rotateAfter = $rotateAfter");
|
verbose("rotateAfter = $rotateAfter");
|
||||||
|
|
||||||
@@ -4534,13 +4621,13 @@ if ($alias && $aliasPath && $passwordMatch) {
|
|||||||
$useCache = false;
|
$useCache = false;
|
||||||
|
|
||||||
is_writable($aliasPath)
|
is_writable($aliasPath)
|
||||||
or errorPage("Directory for alias is not writable.");
|
or errorPage("Directory for alias is not writable.", 403);
|
||||||
|
|
||||||
preg_match($validAliasname, $alias)
|
preg_match($validAliasname, $alias)
|
||||||
or errorPage('Filename for alias contains invalid characters. Do not add extension.');
|
or errorPage('Filename for alias contains invalid characters. Do not add extension.', 404);
|
||||||
|
|
||||||
} elseif ($alias) {
|
} elseif ($alias) {
|
||||||
errorPage('Alias is not enabled in the config file or password not matching.');
|
errorPage('Alias is not enabled in the config file or password not matching.', 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("alias = $alias");
|
verbose("alias = $alias");
|
||||||
@@ -4592,12 +4679,48 @@ if ($dummyImage === true) {
|
|||||||
|
|
||||||
$srcImage = $img->getTarget();
|
$srcImage = $img->getTarget();
|
||||||
$imagePath = null;
|
$imagePath = null;
|
||||||
|
|
||||||
verbose("src (updated) = $srcImage");
|
verbose("src (updated) = $srcImage");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare a sRGB version of the image and use it as source image.
|
||||||
|
*/
|
||||||
|
$srgbDirName = "/srgb";
|
||||||
|
$srgbDir = realpath(getConfig('srgb_dir', $cachePath . $srgbDirName));
|
||||||
|
$srgbDefault = getConfig('srgb_default', false);
|
||||||
|
$srgbColorProfile = getConfig('srgb_colorprofile', __DIR__ . '/../icc/sRGB_IEC61966-2-1_black_scaled.icc');
|
||||||
|
$srgb = getDefined('srgb', true, null);
|
||||||
|
|
||||||
|
if ($srgb || $srgbDefault) {
|
||||||
|
|
||||||
|
if (!is_writable($srgbDir)) {
|
||||||
|
if (is_writable($cachePath)) {
|
||||||
|
mkdir($srgbDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = $img->convert2sRGBColorSpace(
|
||||||
|
$srcImage,
|
||||||
|
$imagePath,
|
||||||
|
$srgbDir,
|
||||||
|
$srgbColorProfile,
|
||||||
|
$useCache
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($filename) {
|
||||||
|
$srcImage = $img->getTarget();
|
||||||
|
$imagePath = null;
|
||||||
|
verbose("srgb conversion and saved to cache = $srcImage");
|
||||||
|
} else {
|
||||||
|
verbose("srgb not op");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display status
|
* Display status
|
||||||
*/
|
*/
|
||||||
@@ -4608,6 +4731,7 @@ if ($status) {
|
|||||||
$text .= "Allow remote images = $allowRemote\n";
|
$text .= "Allow remote images = $allowRemote\n";
|
||||||
$text .= "Cache writable = " . is_writable($cachePath) . "\n";
|
$text .= "Cache writable = " . is_writable($cachePath) . "\n";
|
||||||
$text .= "Cache dummy writable = " . is_writable($dummyDir) . "\n";
|
$text .= "Cache dummy writable = " . is_writable($dummyDir) . "\n";
|
||||||
|
$text .= "Cache srgb writable = " . is_writable($srgbDir) . "\n";
|
||||||
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
||||||
|
|
||||||
$no = extension_loaded('exif') ? null : 'NOT';
|
$no = extension_loaded('exif') ? null : 'NOT';
|
||||||
@@ -4616,6 +4740,9 @@ if ($status) {
|
|||||||
$no = extension_loaded('curl') ? null : 'NOT';
|
$no = extension_loaded('curl') ? null : 'NOT';
|
||||||
$text .= "Extension curl is $no loaded.<br>";
|
$text .= "Extension curl is $no loaded.<br>";
|
||||||
|
|
||||||
|
$no = extension_loaded('imagick') ? null : 'NOT';
|
||||||
|
$text .= "Extension imagick is $no loaded.<br>";
|
||||||
|
|
||||||
$no = extension_loaded('gd') ? null : 'NOT';
|
$no = extension_loaded('gd') ? null : 'NOT';
|
||||||
$text .= "Extension gd is $no loaded.<br>";
|
$text .= "Extension gd is $no loaded.<br>";
|
||||||
|
|
||||||
@@ -4651,7 +4778,7 @@ $hookBeforeCImage = getConfig('hook_before_CImage', null);
|
|||||||
|
|
||||||
if (is_callable($hookBeforeCImage)) {
|
if (is_callable($hookBeforeCImage)) {
|
||||||
verbose("hookBeforeCImage activated");
|
verbose("hookBeforeCImage activated");
|
||||||
|
|
||||||
$allConfig = $hookBeforeCImage($img, array(
|
$allConfig = $hookBeforeCImage($img, array(
|
||||||
// Options for calculate dimensions
|
// Options for calculate dimensions
|
||||||
'newWidth' => $newWidth,
|
'newWidth' => $newWidth,
|
||||||
@@ -4684,7 +4811,7 @@ if (is_callable($hookBeforeCImage)) {
|
|||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => $outputFormat,
|
'outputFormat' => $outputFormat,
|
||||||
'dpr' => $dpr,
|
'dpr' => $dpr,
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
'postProcessing' => $postProcessing,
|
'postProcessing' => $postProcessing,
|
||||||
));
|
));
|
||||||
|
10
webroot/imgs.php
Executable file → Normal file
10
webroot/imgs.php
Executable file → Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user