mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-04 15:17:42 +02:00
One can now add a HTTP header for Cache-Control in the config file, #109.
This commit is contained in:
32
CImage.php
32
CImage.php
@@ -63,6 +63,13 @@ class CImage
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add HTTP headers for outputing image.
|
||||
*/
|
||||
private $HTTPHeader = array();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Default background color, red, green, blue, alpha.
|
||||
*
|
||||
@@ -2422,11 +2429,28 @@ class CImage
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add HTTP header for putputting together with image.
|
||||
*
|
||||
* @param string $type the header type such as "Cache-Control"
|
||||
* @param string $value the value to use
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHTTPHeader($type, $value)
|
||||
{
|
||||
$this->HTTPHeader[$type] = $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Output image to browser using caching.
|
||||
*
|
||||
* @param string $file to read and output, default is to use $this->cacheFileName
|
||||
* @param string $format set to json to output file as json object with details
|
||||
* @param string $file to read and output, default is to
|
||||
* use $this->cacheFileName
|
||||
* @param string $format set to json to output file as json
|
||||
* object with details
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -2463,6 +2487,10 @@ class CImage
|
||||
header('Last-Modified: ' . $gmdate . " GMT");
|
||||
}
|
||||
|
||||
foreach($this->HTTPHeader as $key => $val) {
|
||||
header("$key: $val");
|
||||
}
|
||||
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified) {
|
||||
|
||||
if ($this->verbose) {
|
||||
|
@@ -8,6 +8,7 @@ Revision history
|
||||
v0.7.6* (2015-10-20)
|
||||
-------------------------------------
|
||||
|
||||
* One can now add a HTTP header for Cache-Control in the config file, #109.
|
||||
* Added hook in img,php before CImage is called, #123.
|
||||
* Added configuration for default jpeg quality and png compression in the config file, #107.
|
||||
* Strip comments and whitespace in imgs.php, #115.
|
||||
|
@@ -928,6 +928,18 @@ $cachePath = getConfig('cache_path', __DIR__ . '/../cache/');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the cachepath from config.
|
||||
*/
|
||||
$cacheControl = getConfig('cache_control', null);
|
||||
|
||||
if ($cacheControl) {
|
||||
verbose("cacheControl = $cacheControl");
|
||||
$img->addHTTPHeader("Cache-Control", $cacheControl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prepare a dummy image and use it as source image.
|
||||
*/
|
||||
|
@@ -140,6 +140,16 @@ return array(
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add header for cache control when outputting images.
|
||||
*
|
||||
* Default value:
|
||||
* cache_control: null, or set to string
|
||||
*/
|
||||
//'cache_control' => "max-age=86400",
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The name representing a dummy image which is automatically created
|
||||
* and stored at the defined path. The dummy image can then be used
|
||||
|
Reference in New Issue
Block a user