mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-29 10:29:47 +02:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1666ea1412 | ||
|
bb57af697b | ||
|
55ce23ae5e | ||
|
4589b3b3cd | ||
|
d5ca10cebc | ||
|
9d7343a2df | ||
|
3d7adcdbde | ||
|
80cd4e092f | ||
|
4c0ac8ed23 | ||
|
39b86628db | ||
|
5f4280d387 | ||
|
dd315dbd21 | ||
|
493118e1c5 | ||
|
e41b3d9877 |
@@ -51,6 +51,15 @@ class CCache
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($create && defined('WINDOWS2WSL')) {
|
||||||
|
// Special case to solve Windows 2 WSL integration
|
||||||
|
$path = $this->path . "/" . $subdir;
|
||||||
|
|
||||||
|
if (mkdir($path)) {
|
||||||
|
return realpath($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($create && is_writable($this->path)) {
|
if ($create && is_writable($this->path)) {
|
||||||
$path = $this->path . "/" . $subdir;
|
$path = $this->path . "/" . $subdir;
|
||||||
|
|
||||||
|
@@ -215,7 +215,7 @@ class CHttpGet
|
|||||||
{
|
{
|
||||||
$type = isset($this->response['header']['Content-Type'])
|
$type = isset($this->response['header']['Content-Type'])
|
||||||
? $this->response['header']['Content-Type']
|
? $this->response['header']['Content-Type']
|
||||||
: null;
|
: '';
|
||||||
|
|
||||||
return preg_match('#[a-z]+/[a-z]+#', $type)
|
return preg_match('#[a-z]+/[a-z]+#', $type)
|
||||||
? $type
|
? $type
|
||||||
|
23
CImage.php
23
CImage.php
@@ -679,9 +679,9 @@ class CImage
|
|||||||
*
|
*
|
||||||
* @return string $extension as a normalized file extension.
|
* @return string $extension as a normalized file extension.
|
||||||
*/
|
*/
|
||||||
private function normalizeFileExtension($extension = null)
|
private function normalizeFileExtension($extension = "")
|
||||||
{
|
{
|
||||||
$extension = strtolower($extension ? $extension : $this->extension);
|
$extension = strtolower($extension ? $extension : $this->extension ?? "");
|
||||||
|
|
||||||
if ($extension == 'jpeg') {
|
if ($extension == 'jpeg') {
|
||||||
$extension = 'jpg';
|
$extension = 'jpg';
|
||||||
@@ -964,8 +964,11 @@ class CImage
|
|||||||
{
|
{
|
||||||
$file = $file ? $file : $this->pathToImage;
|
$file = $file ? $file : $this->pathToImage;
|
||||||
|
|
||||||
is_readable($file)
|
// Special case to solve Windows 2 WSL integration
|
||||||
or $this->raiseError('Image file does not exist.');
|
if (!defined('WINDOWS2WSL')) {
|
||||||
|
is_readable($file)
|
||||||
|
or $this->raiseError('Image file does not exist.');
|
||||||
|
}
|
||||||
|
|
||||||
$info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
|
$info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
|
||||||
if (empty($info)) {
|
if (empty($info)) {
|
||||||
@@ -2440,8 +2443,10 @@ class CImage
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_writable($this->saveFolder)
|
if (!defined("WINDOWS2WSL")) {
|
||||||
|
is_writable($this->saveFolder)
|
||||||
or $this->raiseError('Target directory is not writable.');
|
or $this->raiseError('Target directory is not writable.');
|
||||||
|
}
|
||||||
|
|
||||||
$type = $this->getTargetImageExtension();
|
$type = $this->getTargetImageExtension();
|
||||||
$this->Log("Saving image as " . $type);
|
$this->Log("Saving image as " . $type);
|
||||||
@@ -2793,18 +2798,18 @@ class CImage
|
|||||||
$lastModified = filemtime($this->pathToImage);
|
$lastModified = filemtime($this->pathToImage);
|
||||||
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$details['cache'] = basename($this->cacheFileName);
|
$details['cache'] = basename($this->cacheFileName ?? "");
|
||||||
$lastModified = filemtime($this->cacheFileName);
|
$lastModified = filemtime($this->cacheFileName ?? "");
|
||||||
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$this->load($file);
|
$this->load($file);
|
||||||
|
|
||||||
$details['filename'] = basename($file);
|
$details['filename'] = basename($file ?? "");
|
||||||
$details['mimeType'] = $this->getMimeType($this->fileType);
|
$details['mimeType'] = $this->getMimeType($this->fileType);
|
||||||
$details['width'] = $this->width;
|
$details['width'] = $this->width;
|
||||||
$details['height'] = $this->height;
|
$details['height'] = $this->height;
|
||||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||||
$details['size'] = filesize($file);
|
$details['size'] = filesize($file ?? "");
|
||||||
$details['colors'] = $this->colorsTotal($this->image);
|
$details['colors'] = $this->colorsTotal($this->image);
|
||||||
$details['includedFiles'] = count(get_included_files());
|
$details['includedFiles'] = count(get_included_files());
|
||||||
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
||||||
|
@@ -2,8 +2,10 @@ Image conversion on the fly using PHP
|
|||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
[](https://gitter.im/mosbth/cimage?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/mosbth/cimage?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
<!--
|
||||||
[](https://travis-ci.org/mosbth/cimage)
|
[](https://travis-ci.org/mosbth/cimage)
|
||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
||||||
|
-->
|
||||||
|
|
||||||
About
|
About
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
29
REVISION.md
29
REVISION.md
@@ -1,8 +1,37 @@
|
|||||||
Revision history
|
Revision history
|
||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
|
<!--
|
||||||
[](https://travis-ci.org/mosbth/cimage)
|
[](https://travis-ci.org/mosbth/cimage)
|
||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
||||||
|
--->
|
||||||
|
|
||||||
|
v0.8.5 (2022-11-17)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* "Enable configuration fix for solving Windows 2 WSL2 issue with is_readable/is_writable #189."
|
||||||
|
* Update CHttpGet.php for php 8.1 deprecated notice #188.
|
||||||
|
* Remove build status from README (since it is not up to date).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
v0.8.4 (2022-05-30)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Support PHP 8.1 and remove (more) deprecated messages when run in in development mode.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
v0.8.3 (2022-05-24)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Support PHP 8.1 and remove deprecated messages when run in in development mode.
|
||||||
|
* Generate prebuilt all include files for various settings
|
||||||
|
* Fix deprecated for PHP 8.1
|
||||||
|
* Fix deprecated for PHP 8.1
|
||||||
|
* Add php version as output in verbose mode
|
||||||
|
* Add PHP 81 as test environment
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
v0.8.2 (2021-10-27)
|
v0.8.2 (2021-10-27)
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.8.2 (2021-10-27)");
|
define("CIMAGE_VERSION", "v0.8.5 (2022-11-17)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
|
@@ -15,6 +15,15 @@ services:
|
|||||||
- "8090:80"
|
- "8090:80"
|
||||||
volumes: [ ".:/home/anax/repo" ]
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php81:
|
||||||
|
image: anax/dev:php81
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php81-apache:
|
||||||
|
image: anax/dev:php81-apache
|
||||||
|
ports: [ "11081:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
php80:
|
php80:
|
||||||
image: anax/dev:php80
|
image: anax/dev:php80
|
||||||
volumes: [ ".:/home/anax/repo" ]
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
@@ -186,7 +186,7 @@ $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array());
|
|||||||
|
|
||||||
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
||||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
||||||
$refererHost = parse_url($referer, PHP_URL_HOST);
|
$refererHost = parse_url($referer ?? "", PHP_URL_HOST);
|
||||||
|
|
||||||
if (!$allowHotlinking) {
|
if (!$allowHotlinking) {
|
||||||
if ($passwordMatch) {
|
if ($passwordMatch) {
|
||||||
@@ -319,11 +319,11 @@ 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.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
// Get settings for src-alt as backup image
|
// Get settings for src-alt as backup image
|
||||||
$srcAltImage = urldecode(get('src-alt', null));
|
$srcAltImage = urldecode(get('src-alt', ""));
|
||||||
$srcAltConfig = getConfig('src_alt', null);
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
if (empty($srcAltImage)) {
|
if (empty($srcAltImage)) {
|
||||||
$srcAltImage = $srcAltConfig;
|
$srcAltImage = $srcAltConfig;
|
||||||
@@ -1149,7 +1149,8 @@ EOD;
|
|||||||
/**
|
/**
|
||||||
* Load, process and output the image
|
* Load, process and output the image
|
||||||
*/
|
*/
|
||||||
$img->log("Incoming arguments: " . print_r(verbose(), 1))
|
$img->log("PHP version: " . phpversion())
|
||||||
|
->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||||
->setSaveFolder($cachePath)
|
->setSaveFolder($cachePath)
|
||||||
->useCache($useCache)
|
->useCache($useCache)
|
||||||
->setSource($srcImage, $imagePath)
|
->setSource($srcImage, $imagePath)
|
||||||
|
@@ -21,6 +21,15 @@ if (!defined("CIMAGE_DEBUG")) {
|
|||||||
define("CIMAGE_DEBUG_FILE", "/tmp/cimage");
|
define("CIMAGE_DEBUG_FILE", "/tmp/cimage");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this if you work with a webserver in Windows and try to access files
|
||||||
|
* within WSL2.
|
||||||
|
* The issue seems to be with functions like `is_writable()` and
|
||||||
|
* `is_readable()`.
|
||||||
|
* When WINDOWS2WSL is defined (to any value) it ignores these functions.
|
||||||
|
*/
|
||||||
|
#define('WINDOWS2WSL', 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
@@ -38,7 +38,7 @@ $config = array(
|
|||||||
|
|
||||||
|
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.8.2 (2021-10-27)");
|
define("CIMAGE_VERSION", "v0.8.5 (2022-11-17)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
@@ -465,7 +465,7 @@ class CHttpGet
|
|||||||
{
|
{
|
||||||
$type = isset($this->response['header']['Content-Type'])
|
$type = isset($this->response['header']['Content-Type'])
|
||||||
? $this->response['header']['Content-Type']
|
? $this->response['header']['Content-Type']
|
||||||
: null;
|
: '';
|
||||||
|
|
||||||
return preg_match('#[a-z]+/[a-z]+#', $type)
|
return preg_match('#[a-z]+/[a-z]+#', $type)
|
||||||
? $type
|
? $type
|
||||||
@@ -1816,9 +1816,9 @@ class CImage
|
|||||||
*
|
*
|
||||||
* @return string $extension as a normalized file extension.
|
* @return string $extension as a normalized file extension.
|
||||||
*/
|
*/
|
||||||
private function normalizeFileExtension($extension = null)
|
private function normalizeFileExtension($extension = "")
|
||||||
{
|
{
|
||||||
$extension = strtolower($extension ? $extension : $this->extension);
|
$extension = strtolower($extension ? $extension : $this->extension ?? "");
|
||||||
|
|
||||||
if ($extension == 'jpeg') {
|
if ($extension == 'jpeg') {
|
||||||
$extension = 'jpg';
|
$extension = 'jpg';
|
||||||
@@ -2101,8 +2101,11 @@ class CImage
|
|||||||
{
|
{
|
||||||
$file = $file ? $file : $this->pathToImage;
|
$file = $file ? $file : $this->pathToImage;
|
||||||
|
|
||||||
is_readable($file)
|
// Special case to solve Windows 2 WSL integration
|
||||||
or $this->raiseError('Image file does not exist.');
|
if (!defined('WINDOWS2WSL')) {
|
||||||
|
is_readable($file)
|
||||||
|
or $this->raiseError('Image file does not exist.');
|
||||||
|
}
|
||||||
|
|
||||||
$info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
|
$info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
|
||||||
if (empty($info)) {
|
if (empty($info)) {
|
||||||
@@ -3577,8 +3580,10 @@ class CImage
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_writable($this->saveFolder)
|
if (!defined("WINDOWS2WSL")) {
|
||||||
|
is_writable($this->saveFolder)
|
||||||
or $this->raiseError('Target directory is not writable.');
|
or $this->raiseError('Target directory is not writable.');
|
||||||
|
}
|
||||||
|
|
||||||
$type = $this->getTargetImageExtension();
|
$type = $this->getTargetImageExtension();
|
||||||
$this->Log("Saving image as " . $type);
|
$this->Log("Saving image as " . $type);
|
||||||
@@ -3930,18 +3935,18 @@ class CImage
|
|||||||
$lastModified = filemtime($this->pathToImage);
|
$lastModified = filemtime($this->pathToImage);
|
||||||
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$details['cache'] = basename($this->cacheFileName);
|
$details['cache'] = basename($this->cacheFileName ?? "");
|
||||||
$lastModified = filemtime($this->cacheFileName);
|
$lastModified = filemtime($this->cacheFileName ?? "");
|
||||||
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$this->load($file);
|
$this->load($file);
|
||||||
|
|
||||||
$details['filename'] = basename($file);
|
$details['filename'] = basename($file ?? "");
|
||||||
$details['mimeType'] = $this->getMimeType($this->fileType);
|
$details['mimeType'] = $this->getMimeType($this->fileType);
|
||||||
$details['width'] = $this->width;
|
$details['width'] = $this->width;
|
||||||
$details['height'] = $this->height;
|
$details['height'] = $this->height;
|
||||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||||
$details['size'] = filesize($file);
|
$details['size'] = filesize($file ?? "");
|
||||||
$details['colors'] = $this->colorsTotal($this->image);
|
$details['colors'] = $this->colorsTotal($this->image);
|
||||||
$details['includedFiles'] = count(get_included_files());
|
$details['includedFiles'] = count(get_included_files());
|
||||||
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
||||||
@@ -4140,6 +4145,15 @@ class CCache
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($create && defined('WINDOWS2WSL')) {
|
||||||
|
// Special case to solve Windows 2 WSL integration
|
||||||
|
$path = $this->path . "/" . $subdir;
|
||||||
|
|
||||||
|
if (mkdir($path)) {
|
||||||
|
return realpath($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($create && is_writable($this->path)) {
|
if ($create && is_writable($this->path)) {
|
||||||
$path = $this->path . "/" . $subdir;
|
$path = $this->path . "/" . $subdir;
|
||||||
|
|
||||||
@@ -4624,7 +4638,7 @@ $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array());
|
|||||||
|
|
||||||
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
||||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
||||||
$refererHost = parse_url($referer, PHP_URL_HOST);
|
$refererHost = parse_url($referer ?? "", PHP_URL_HOST);
|
||||||
|
|
||||||
if (!$allowHotlinking) {
|
if (!$allowHotlinking) {
|
||||||
if ($passwordMatch) {
|
if ($passwordMatch) {
|
||||||
@@ -4757,11 +4771,11 @@ 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.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
// Get settings for src-alt as backup image
|
// Get settings for src-alt as backup image
|
||||||
$srcAltImage = urldecode(get('src-alt', null));
|
$srcAltImage = urldecode(get('src-alt', ""));
|
||||||
$srcAltConfig = getConfig('src_alt', null);
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
if (empty($srcAltImage)) {
|
if (empty($srcAltImage)) {
|
||||||
$srcAltImage = $srcAltConfig;
|
$srcAltImage = $srcAltConfig;
|
||||||
@@ -5587,7 +5601,8 @@ EOD;
|
|||||||
/**
|
/**
|
||||||
* Load, process and output the image
|
* Load, process and output the image
|
||||||
*/
|
*/
|
||||||
$img->log("Incoming arguments: " . print_r(verbose(), 1))
|
$img->log("PHP version: " . phpversion())
|
||||||
|
->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||||
->setSaveFolder($cachePath)
|
->setSaveFolder($cachePath)
|
||||||
->useCache($useCache)
|
->useCache($useCache)
|
||||||
->setSource($srcImage, $imagePath)
|
->setSource($srcImage, $imagePath)
|
||||||
|
@@ -38,7 +38,7 @@ $config = array(
|
|||||||
|
|
||||||
|
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.8.2 (2021-10-27)");
|
define("CIMAGE_VERSION", "v0.8.5 (2022-11-17)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
@@ -465,7 +465,7 @@ class CHttpGet
|
|||||||
{
|
{
|
||||||
$type = isset($this->response['header']['Content-Type'])
|
$type = isset($this->response['header']['Content-Type'])
|
||||||
? $this->response['header']['Content-Type']
|
? $this->response['header']['Content-Type']
|
||||||
: null;
|
: '';
|
||||||
|
|
||||||
return preg_match('#[a-z]+/[a-z]+#', $type)
|
return preg_match('#[a-z]+/[a-z]+#', $type)
|
||||||
? $type
|
? $type
|
||||||
@@ -1816,9 +1816,9 @@ class CImage
|
|||||||
*
|
*
|
||||||
* @return string $extension as a normalized file extension.
|
* @return string $extension as a normalized file extension.
|
||||||
*/
|
*/
|
||||||
private function normalizeFileExtension($extension = null)
|
private function normalizeFileExtension($extension = "")
|
||||||
{
|
{
|
||||||
$extension = strtolower($extension ? $extension : $this->extension);
|
$extension = strtolower($extension ? $extension : $this->extension ?? "");
|
||||||
|
|
||||||
if ($extension == 'jpeg') {
|
if ($extension == 'jpeg') {
|
||||||
$extension = 'jpg';
|
$extension = 'jpg';
|
||||||
@@ -2101,8 +2101,11 @@ class CImage
|
|||||||
{
|
{
|
||||||
$file = $file ? $file : $this->pathToImage;
|
$file = $file ? $file : $this->pathToImage;
|
||||||
|
|
||||||
is_readable($file)
|
// Special case to solve Windows 2 WSL integration
|
||||||
or $this->raiseError('Image file does not exist.');
|
if (!defined('WINDOWS2WSL')) {
|
||||||
|
is_readable($file)
|
||||||
|
or $this->raiseError('Image file does not exist.');
|
||||||
|
}
|
||||||
|
|
||||||
$info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
|
$info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
|
||||||
if (empty($info)) {
|
if (empty($info)) {
|
||||||
@@ -3577,8 +3580,10 @@ class CImage
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_writable($this->saveFolder)
|
if (!defined("WINDOWS2WSL")) {
|
||||||
|
is_writable($this->saveFolder)
|
||||||
or $this->raiseError('Target directory is not writable.');
|
or $this->raiseError('Target directory is not writable.');
|
||||||
|
}
|
||||||
|
|
||||||
$type = $this->getTargetImageExtension();
|
$type = $this->getTargetImageExtension();
|
||||||
$this->Log("Saving image as " . $type);
|
$this->Log("Saving image as " . $type);
|
||||||
@@ -3930,18 +3935,18 @@ class CImage
|
|||||||
$lastModified = filemtime($this->pathToImage);
|
$lastModified = filemtime($this->pathToImage);
|
||||||
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$details['cache'] = basename($this->cacheFileName);
|
$details['cache'] = basename($this->cacheFileName ?? "");
|
||||||
$lastModified = filemtime($this->cacheFileName);
|
$lastModified = filemtime($this->cacheFileName ?? "");
|
||||||
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$this->load($file);
|
$this->load($file);
|
||||||
|
|
||||||
$details['filename'] = basename($file);
|
$details['filename'] = basename($file ?? "");
|
||||||
$details['mimeType'] = $this->getMimeType($this->fileType);
|
$details['mimeType'] = $this->getMimeType($this->fileType);
|
||||||
$details['width'] = $this->width;
|
$details['width'] = $this->width;
|
||||||
$details['height'] = $this->height;
|
$details['height'] = $this->height;
|
||||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||||
$details['size'] = filesize($file);
|
$details['size'] = filesize($file ?? "");
|
||||||
$details['colors'] = $this->colorsTotal($this->image);
|
$details['colors'] = $this->colorsTotal($this->image);
|
||||||
$details['includedFiles'] = count(get_included_files());
|
$details['includedFiles'] = count(get_included_files());
|
||||||
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
||||||
@@ -4140,6 +4145,15 @@ class CCache
|
|||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($create && defined('WINDOWS2WSL')) {
|
||||||
|
// Special case to solve Windows 2 WSL integration
|
||||||
|
$path = $this->path . "/" . $subdir;
|
||||||
|
|
||||||
|
if (mkdir($path)) {
|
||||||
|
return realpath($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($create && is_writable($this->path)) {
|
if ($create && is_writable($this->path)) {
|
||||||
$path = $this->path . "/" . $subdir;
|
$path = $this->path . "/" . $subdir;
|
||||||
|
|
||||||
@@ -4624,7 +4638,7 @@ $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array());
|
|||||||
|
|
||||||
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
||||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
||||||
$refererHost = parse_url($referer, PHP_URL_HOST);
|
$refererHost = parse_url($referer ?? "", PHP_URL_HOST);
|
||||||
|
|
||||||
if (!$allowHotlinking) {
|
if (!$allowHotlinking) {
|
||||||
if ($passwordMatch) {
|
if ($passwordMatch) {
|
||||||
@@ -4757,11 +4771,11 @@ 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.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
// Get settings for src-alt as backup image
|
// Get settings for src-alt as backup image
|
||||||
$srcAltImage = urldecode(get('src-alt', null));
|
$srcAltImage = urldecode(get('src-alt', ""));
|
||||||
$srcAltConfig = getConfig('src_alt', null);
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
if (empty($srcAltImage)) {
|
if (empty($srcAltImage)) {
|
||||||
$srcAltImage = $srcAltConfig;
|
$srcAltImage = $srcAltConfig;
|
||||||
@@ -5587,7 +5601,8 @@ EOD;
|
|||||||
/**
|
/**
|
||||||
* Load, process and output the image
|
* Load, process and output the image
|
||||||
*/
|
*/
|
||||||
$img->log("Incoming arguments: " . print_r(verbose(), 1))
|
$img->log("PHP version: " . phpversion())
|
||||||
|
->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||||
->setSaveFolder($cachePath)
|
->setSaveFolder($cachePath)
|
||||||
->useCache($useCache)
|
->useCache($useCache)
|
||||||
->setSource($srcImage, $imagePath)
|
->setSource($srcImage, $imagePath)
|
||||||
|
File diff suppressed because one or more lines are too long
22
webroot/tests.php
Normal file
22
webroot/tests.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$links = [
|
||||||
|
"img.php?src=car.png&v",
|
||||||
|
"img.php?src=car.png&w=700&v",
|
||||||
|
];
|
||||||
|
|
||||||
|
?><!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Links to use for testing</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Links useful for testing</h1>
|
||||||
|
<p>A collection of linkt to use to test various aspects of the cimage process.</p>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($links as $link) : ?>
|
||||||
|
<li><a href="<?= $link ?>"><?= $link ?></a></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user