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

Compare commits

...

14 Commits

Author SHA1 Message Date
Mikael Roos
c563275ed5 Support PHP 7.4, some minor fixes with notices. 2020-01-15 16:51:39 +01:00
Mikael Roos
8fec09b195 Merge pull request #176 from SpaceLenore/patch-1
fixed markdown syntax
2018-10-28 19:08:45 +01:00
Lenore
ac16343cd7 fixed markdown syntax
added spaces so the markdown gets parsed correctly
2018-10-28 17:49:35 +01:00
Mikael Roos
cd142c5880 prepare to tag 2017-11-06 10:24:47 +01:00
Mikael Roos
91dd92d483 Remove webroot/img/{round8.PNG,wider.JPEG,wider.JPG} to avoid unzip warning message when installing with composer. 2017-11-06 10:24:16 +01:00
Mikael Roos
4b64d921d1 Adding docker-compose.yml #169. 2017-06-26 10:30:21 +02:00
Mikael Roos
4211d7e0e6 Adding docker-compose.yml #169. 2017-06-26 10:30:08 +02:00
Mikael Roos
dd8878c8bd add issue number 2017-03-31 00:55:38 +02:00
Mikael Roos
f9604518e4 prepare to tag v0.7.19 2017-03-31 00:47:55 +02:00
Mikael Roos
61aa52854e Move exception handler from functions.php to img.php. 2017-03-31 00:46:43 +02:00
Mikael Roos
401478c839 Correct XSS injection in check_system.php. 2016-08-31 15:26:14 +02:00
Mikael Roos
f0ab9479d6 read lena.tif, will need it in the future 2016-08-13 18:33:09 +02:00
Mikael Roos
9ff7a61ca9 remove tif version of lena 2016-08-13 17:49:36 +02:00
Mikael Roos
3170beb832 Composer suggests ext-imagick and ext-curl. 2016-08-11 17:39:45 +02:00
16 changed files with 162 additions and 103 deletions

View File

@@ -1023,13 +1023,15 @@ class CImage
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
// width as %
if ($this->newWidth[strlen($this->newWidth)-1] == '%') {
if ($this->newWidth
&& $this->newWidth[strlen($this->newWidth)-1] == '%') {
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
$this->log("Setting new width based on % to {$this->newWidth}");
}
// height as %
if ($this->newHeight[strlen($this->newHeight)-1] == '%') {
if ($this->newHeight
&& $this->newHeight[strlen($this->newHeight)-1] == '%') {
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
$this->log("Setting new height based on % to {$this->newHeight}");
}

View File

@@ -45,7 +45,7 @@ There are several ways of installing. You either install the whole project which
###Install source from GitHub
### Install source from GitHub
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).
@@ -66,7 +66,7 @@ chmod 777 cache
```
###Install all-included bundle
### Install all-included bundle
There are some all-included bundles of `img.php` that can be downloaded and used without dependency to the rest of the sourcecode.
@@ -86,7 +86,7 @@ Open up the file in your editor and edit the array `$config`. Ensure that the pa
###Install from Packagist
### Install from Packagist
You can install the package [`mos/cimage` from Packagist](https://packagist.org/packages/mos/cimage) using composer.
@@ -139,13 +139,13 @@ Get going quickly
###Check out the test page
### Check out the test page
Try it out by pointing your browser to the test file `webroot/test/test.php`. It will show some example images and you can review how they are created.
###Process your first image
### Process your first image
<img src="https://cimage.se/cimage/imgd.php?src=example/kodim04.png&amp;w=w2&amp;a=40,0,50,0" alt=''>
@@ -159,20 +159,20 @@ and try to resize it to a thumbnail by adding the options
###What does "processing the image" involves?
### 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 and those who seek a deeper understanding on how it works behind the scene.
###Check your system
### Check your system
Open up `webroot/check_system.php` if you are uncertain that your system has the right extensions loaded.
###How does it work?
### How does it work?
Review the settings in `webroot/img_config.php` and check out `webroot/img.php` on how it uses `CImage`.
@@ -193,7 +193,7 @@ Basic usage
###Select the source
### Select the source
Open an image through `img.php` by using its `src` attribute.
@@ -209,7 +209,7 @@ All images are stored in a directory structure and you access them as:
###Resize using constraints on width and height
### Resize using constraints on width and height
Create a thumbnail of the image by applying constraints on width and height, or one of them.
@@ -223,7 +223,7 @@ Think of the constraints as a imaginary box where the image should fit. With `wi
###Resize to fit a certain dimension
### 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*.
@@ -243,7 +243,7 @@ Fill to fit is useful when you have some image that must fit in a certain dimens
###List of parameters
### 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.
@@ -255,7 +255,7 @@ Fill to fit is useful when you have some image that must fit in a certain dimens
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
#### Mandatory options and debugging
Option `src` is the only mandatory option. The options in this section is useful for debugging or deciding what version of the target image is used.
@@ -270,7 +270,7 @@ Option `src` is the only mandatory option. The options in this section is useful
####Options for deciding width and height of target image
#### Options for deciding width and height of target image
These options are all affecting the final dimensions, width and height, of the resulting image.
@@ -283,7 +283,7 @@ These options are all affecting the final dimensions, width and height, of the r
####Options for resize strategy
#### 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.
@@ -296,7 +296,7 @@ These options affect strategy to use when resizing an image into a target image
####Options for cropping part of image
#### Options for cropping part of image
These options enable to decide what part of image to crop out.
@@ -307,7 +307,7 @@ These options enable to decide what part of image to crop out.
####General processing options
#### General processing options
These options are general options affecting processing.
@@ -317,7 +317,7 @@ These options are general options affecting processing.
####Processing of image before resizing
#### Processing of image before resizing
This option are executed *before* the image is resized.
@@ -329,7 +329,7 @@ This option are executed *before* the image is resized.
####Processing of image after resizing
#### Processing of image after resizing
These options are executed *after* the image is resized.
@@ -347,7 +347,7 @@ These options are executed *after* the image is resized.
####Saving image, affecting quality and file size
#### Saving image, affecting quality and file size
Options for saving the target image.
@@ -403,7 +403,7 @@ Consult the file `webroot/img-config.php` for a complete list together with the
###Create and name the config file
### Create and name the config file
The file `img.php` looks for the config-file `img_config.php`, and uses it if its found. The three files where everything is included -- `imgd.php`, `imgp.php` and `imgs.php` -- includes an empty `$config`-array which can be overridden by saving a config-file in the same directory. If the script is `imgp.php` then name the config-file `imgp_config.php` and it will find it and use those settings.
@@ -468,19 +468,19 @@ Here are some thoughts when applying `img.php` on a live system.
###Select the proper mode
### Select the proper mode
Select the proper mode for `img.php`. Set it to "strict" or "production" to prevent outsiders to get information about your system. Use only "development" for internal use since its quite verbose in its nature of error reporting.
###Put the installation directory outside web root
### Put the installation directory outside web root
Edit the config file to put the installation directory -- and the cache directory -- outside of the web root. Best practice would be to store the installation directory and cache, outside of the web root. The only thing needed in the web root is `img.php` and `img_config.php` (if used) which can be placed, for example, in `/img/img.php` or just as `/img.php`.
###Friendly urls through `.htaccess`
### Friendly urls through `.htaccess`
Use `.htaccess`and rewrite rules (Apache) to get friendly image urls. Put `img.php` in the `/img` directory. Put the file `.htaccess` in the web root.
@@ -518,7 +518,7 @@ The result is good readable urls to your images. Its easy for the search engine
###Monitor cache size
### Monitor cache size
There is a utility `cache.bash` included for monitoring the size of the cache-directory. It generates an output like this.
@@ -556,13 +556,13 @@ Use it as a base if you feel the need to monitor the size och the cache-director
###Read-only cache
### Read-only cache
The cache directory need to be writable for `img.php` to create new files. But its possible to first create all cache-files and then set the directory to be read-only. This will give you a way of shutting of `img.php` from creating new cache files. `img.php` will then continue to work for all images having a cached version but will fail if someone tries to create a new, not previously cached, version of the image.
###Post-processing with external tools
### Post-processing with external tools
You can use external tools to post-process the images to optimize the file size. This option is available for JPEG and for PNG images. Post-processing is disabled by default, edit `img_config.php` to enable it.
@@ -572,7 +572,7 @@ These tools for post processing is not a part of `CImage` and `img.php`, you nee
###Allowing remote download of images
### Allowing remote download of images
You can allow `img.php` to download remote images. That can be enabled in the config-file. However, before doing so, consider the implications on allowing anyone to download a file, hopefully an image, to your server and then the possibility to access it through the webserver.

View File

@@ -5,6 +5,27 @@ Revision history
[![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
v0.7.21 (2020-01-15)
-------------------------------------
* Support PHP 7.4, some minor fixes with notices.
v0.7.20 (2017-11-06)
-------------------------------------
* Remove webroot/img/{round8.PNG,wider.JPEG,wider.JPG} to avoid unzip warning message when installing with composer.
* Adding docker-compose.yml #169.
v0.7.19 (2017-03-31)
-------------------------------------
* Move exception handler from functions.php to img.php #166.
* Correct XSS injection in `check_system.php`.
* Composer suggests ext-imagick and ext-curl.
v0.7.18 (2016-08-09)
-------------------------------------

View File

@@ -22,7 +22,9 @@
"ext-gd": "*"
},
"suggest": {
"ext-exif": "*"
"ext-exif": "*",
"ext-curl": "*",
"ext-imagick": "*"
},
"autoload": {
"files": [

View File

@@ -1,6 +1,6 @@
<?php
// Version of cimage and img.php
define("CIMAGE_VERSION", "v0.7.18 (2016-08-09)");
define("CIMAGE_VERSION", "v0.7.20 (2017-11-06)");
// For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);

30
docker-compose.yml Normal file
View File

@@ -0,0 +1,30 @@
version: "3"
services:
php74:
image: anax/dev:php74-apache
ports:
- "8074:80"
volumes:
- .:/home/anax/repo
php71:
image: cimage/php71-apache:latest
#build: .
ports:
- "8071:80"
volumes:
- ./:/var/www/html/
php70:
image: cimage/php70-apache:latest
#build: .
ports:
- "8070:80"
volumes:
- .:/var/www/html
php56:
image: cimage/php56-apache:latest
#build: .
ports:
- "8056:80"
volumes:
- .:/var/www/html

View File

@@ -67,22 +67,6 @@ function errorPage($msg, $type = 500)
/**
* Custom exception handler.
*/
set_exception_handler(function ($exception) {
errorPage(
"<p><b>img.php: Uncaught exception:</b> <p>"
. $exception->getMessage()
. "</p><pre>"
. $exception->getTraceAsString()
. "</pre>",
500
);
});
/**
* Get input from query string or return default value if not set.
*

View File

@@ -2,7 +2,7 @@
echo 'Current PHP version: ' . phpversion() . '<br><br>';
echo 'Running on: ' . $_SERVER['SERVER_SOFTWARE'] . '<br><br>';
echo 'Running on: ' . htmlentities($_SERVER['SERVER_SOFTWARE']) . '<br><br>';
$no = extension_loaded('exif') ? null : 'NOT';
echo "Extension exif is $no loaded.<br>";

View File

@@ -8,6 +8,22 @@
*
*/
/**
* Custom exception handler.
*/
set_exception_handler(function ($exception) {
errorPage(
"<p><b>img.php: Uncaught exception:</b> <p>"
. $exception->getMessage()
. "</p><pre>"
. $exception->getTraceAsString()
. "</pre>",
500
);
});
/**
* Get configuration options from file, if the file exists, else use $config
* if its defined or create an empty $config.
@@ -424,7 +440,7 @@ if (isset($sizes[$newWidth])) {
}
// Support width as % of original width
if ($newWidth[strlen($newWidth)-1] == '%') {
if ($newWidth && $newWidth[strlen($newWidth)-1] == '%') {
is_numeric(substr($newWidth, 0, -1))
or errorPage('Width % not numeric.', 404);
} else {
@@ -449,7 +465,7 @@ if (isset($sizes[$newHeight])) {
}
// height
if ($newHeight[strlen($newHeight)-1] == '%') {
if ($newHeight && $newHeight[strlen($newHeight)-1] == '%') {
is_numeric(substr($newHeight, 0, -1))
or errorPage('Height % out of range.', 404);
} else {
@@ -480,7 +496,7 @@ $aspectRatioConstant = getConfig('aspect_ratio_constant', function () {
// Check to replace predefined aspect ratio
$aspectRatios = call_user_func($aspectRatioConstant);
$negateAspectRatio = ($aspectRatio[0] == '!') ? true : false;
$negateAspectRatio = ($aspectRatio && $aspectRatio[0] == '!') ? true : false;
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
if (isset($aspectRatios[$aspectRatio])) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

View File

@@ -41,7 +41,7 @@ return array(
* mode: 'production'
*/
//'mode' => 'production',
//'mode' => 'development',
'mode' => 'development',
//'mode' => 'strict',
@@ -67,7 +67,7 @@ return array(
*/
'image_path' => __DIR__ . '/img/',
'cache_path' => __DIR__ . '/../cache/',
//'alias_path' => __DIR__ . '/img/alias/',
'alias_path' => __DIR__ . '/img/alias/',
@@ -116,7 +116,7 @@ return array(
* password_type: 'text' // use plain password, not encoded,
*/
//'password_always' => false, // always require password,
//'password' => false, // "secret-password",
'password' => "moped", // "secret-password",
//'password_type' => 'text', // supports 'text', 'md5', 'hash',

View File

@@ -38,7 +38,7 @@ $config = array(
// Version of cimage and img.php
define("CIMAGE_VERSION", "v0.7.18 (2016-08-09)");
define("CIMAGE_VERSION", "v0.7.20 (2017-11-06)");
// For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
@@ -118,22 +118,6 @@ function errorPage($msg, $type = 500)
/**
* Custom exception handler.
*/
set_exception_handler(function ($exception) {
errorPage(
"<p><b>img.php: Uncaught exception:</b> <p>"
. $exception->getMessage()
. "</p><pre>"
. $exception->getTraceAsString()
. "</pre>",
500
);
});
/**
* Get input from query string or return default value if not set.
*
@@ -2149,13 +2133,15 @@ class CImage
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
// width as %
if ($this->newWidth[strlen($this->newWidth)-1] == '%') {
if ($this->newWidth
&& $this->newWidth[strlen($this->newWidth)-1] == '%') {
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
$this->log("Setting new width based on % to {$this->newWidth}");
}
// height as %
if ($this->newHeight[strlen($this->newHeight)-1] == '%') {
if ($this->newHeight
&& $this->newHeight[strlen($this->newHeight)-1] == '%') {
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
$this->log("Setting new height based on % to {$this->newHeight}");
}
@@ -4418,6 +4404,22 @@ class CFastTrackCache
*
*/
/**
* Custom exception handler.
*/
set_exception_handler(function ($exception) {
errorPage(
"<p><b>img.php: Uncaught exception:</b> <p>"
. $exception->getMessage()
. "</p><pre>"
. $exception->getTraceAsString()
. "</pre>",
500
);
});
/**
* Get configuration options from file, if the file exists, else use $config
* if its defined or create an empty $config.
@@ -4834,7 +4836,7 @@ if (isset($sizes[$newWidth])) {
}
// Support width as % of original width
if ($newWidth[strlen($newWidth)-1] == '%') {
if ($newWidth && $newWidth[strlen($newWidth)-1] == '%') {
is_numeric(substr($newWidth, 0, -1))
or errorPage('Width % not numeric.', 404);
} else {
@@ -4859,7 +4861,7 @@ if (isset($sizes[$newHeight])) {
}
// height
if ($newHeight[strlen($newHeight)-1] == '%') {
if ($newHeight && $newHeight[strlen($newHeight)-1] == '%') {
is_numeric(substr($newHeight, 0, -1))
or errorPage('Height % out of range.', 404);
} else {
@@ -4890,7 +4892,7 @@ $aspectRatioConstant = getConfig('aspect_ratio_constant', function () {
// Check to replace predefined aspect ratio
$aspectRatios = call_user_func($aspectRatioConstant);
$negateAspectRatio = ($aspectRatio[0] == '!') ? true : false;
$negateAspectRatio = ($aspectRatio && $aspectRatio[0] == '!') ? true : false;
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
if (isset($aspectRatios[$aspectRatio])) {

View File

@@ -38,7 +38,7 @@ $config = array(
// Version of cimage and img.php
define("CIMAGE_VERSION", "v0.7.18 (2016-08-09)");
define("CIMAGE_VERSION", "v0.7.20 (2017-11-06)");
// For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
@@ -118,22 +118,6 @@ function errorPage($msg, $type = 500)
/**
* Custom exception handler.
*/
set_exception_handler(function ($exception) {
errorPage(
"<p><b>img.php: Uncaught exception:</b> <p>"
. $exception->getMessage()
. "</p><pre>"
. $exception->getTraceAsString()
. "</pre>",
500
);
});
/**
* Get input from query string or return default value if not set.
*
@@ -2149,13 +2133,15 @@ class CImage
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
// width as %
if ($this->newWidth[strlen($this->newWidth)-1] == '%') {
if ($this->newWidth
&& $this->newWidth[strlen($this->newWidth)-1] == '%') {
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
$this->log("Setting new width based on % to {$this->newWidth}");
}
// height as %
if ($this->newHeight[strlen($this->newHeight)-1] == '%') {
if ($this->newHeight
&& $this->newHeight[strlen($this->newHeight)-1] == '%') {
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
$this->log("Setting new height based on % to {$this->newHeight}");
}
@@ -4418,6 +4404,22 @@ class CFastTrackCache
*
*/
/**
* Custom exception handler.
*/
set_exception_handler(function ($exception) {
errorPage(
"<p><b>img.php: Uncaught exception:</b> <p>"
. $exception->getMessage()
. "</p><pre>"
. $exception->getTraceAsString()
. "</pre>",
500
);
});
/**
* Get configuration options from file, if the file exists, else use $config
* if its defined or create an empty $config.
@@ -4834,7 +4836,7 @@ if (isset($sizes[$newWidth])) {
}
// Support width as % of original width
if ($newWidth[strlen($newWidth)-1] == '%') {
if ($newWidth && $newWidth[strlen($newWidth)-1] == '%') {
is_numeric(substr($newWidth, 0, -1))
or errorPage('Width % not numeric.', 404);
} else {
@@ -4859,7 +4861,7 @@ if (isset($sizes[$newHeight])) {
}
// height
if ($newHeight[strlen($newHeight)-1] == '%') {
if ($newHeight && $newHeight[strlen($newHeight)-1] == '%') {
is_numeric(substr($newHeight, 0, -1))
or errorPage('Height % out of range.', 404);
} else {
@@ -4890,7 +4892,7 @@ $aspectRatioConstant = getConfig('aspect_ratio_constant', function () {
// Check to replace predefined aspect ratio
$aspectRatios = call_user_func($aspectRatioConstant);
$negateAspectRatio = ($aspectRatio[0] == '!') ? true : false;
$negateAspectRatio = ($aspectRatio && $aspectRatio[0] == '!') ? true : false;
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
if (isset($aspectRatios[$aspectRatio])) {

File diff suppressed because one or more lines are too long