mirror of
https://github.com/mosbth/cimage.git
synced 2025-07-31 21:40:12 +02:00
adding feature for creating dummy images, #101
This commit is contained in:
@@ -373,10 +373,20 @@ $imagePath = getConfig('image_path', __DIR__ . '/img/');
|
||||
$imagePathConstraint = getConfig('image_path_constraint', true);
|
||||
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
|
||||
|
||||
// Dumm image feature
|
||||
$dummyEnabled = getConfig('dummy_enabled', true);
|
||||
$dummyFilename = getConfig('dummy_filename', 'dummy');
|
||||
$dummyImage = false;
|
||||
|
||||
preg_match($validFilename, $srcImage)
|
||||
or errorPage('Filename contains invalid characters.');
|
||||
|
||||
if ($allowRemote && $img->isRemoteSource($srcImage)) {
|
||||
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||
|
||||
// Prepare to create a dummy image and use it as the source image.
|
||||
$dummyImage = true;
|
||||
|
||||
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
|
||||
|
||||
// If source is a remote file, ignore local file checks.
|
||||
|
||||
@@ -933,9 +943,43 @@ if ($verboseFile) {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load, process and output the image
|
||||
*/
|
||||
/**
|
||||
* Set basic options for image processing.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Prepare a dummy image and use it as source image.
|
||||
*/
|
||||
if ($dummyImage === true) {
|
||||
|
||||
$dummyDir = getConfig('dummy_dir', $cachePath. "/" . $dummyFilename);
|
||||
|
||||
is_writable($dummyDir)
|
||||
or verbose("dummy dir not writable = $dummyDir");
|
||||
|
||||
$img->setSaveFolder($dummyDir)
|
||||
->setSource($dummyFilename, $dummyDir)
|
||||
->setOptions(
|
||||
array(
|
||||
'bgColor' => $bgColor,
|
||||
)
|
||||
)
|
||||
->createDummyImage()
|
||||
->generateFilename(null, false)
|
||||
->save(null, null, false);
|
||||
|
||||
$srcImage = $img->getTarget();
|
||||
$imagePath = null;
|
||||
|
||||
verbose("src (updated) = $srcImage");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load, process and output the image
|
||||
*/
|
||||
$img->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||
->setSaveFolder($cachePath)
|
||||
->useCache($useCache)
|
||||
|
@@ -109,6 +109,28 @@ return array(
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The name representing a dummy image which is automatically created
|
||||
* and stored at the defined path. The dummy image can then be used
|
||||
* inplace of an original image as a placeholder.
|
||||
* The dummy_dir must be writable and it defaults to a subdir of the
|
||||
* cache directory.
|
||||
* Write protect the dummy_dir to prevent creation of new dummy images,
|
||||
* but continue to use the existing ones.
|
||||
*
|
||||
* Default value:
|
||||
* dummy_enabled: true as default, disable dummy feature by setting
|
||||
* to false.
|
||||
* dummy_filename: 'dummy' use this as ?src=dummy to create a dummy image.
|
||||
* dummy_dir: Defaults to subdirectory of 'cache_path',
|
||||
* named the same as 'dummy_filename'
|
||||
*/
|
||||
//'dummy_enabled' => true,
|
||||
//'dummy_filename' => 'dummy',
|
||||
//'dummy_dir' => 'some writable directory',
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check that the imagefile is a file below 'image_path' using realpath().
|
||||
* Security constraint to avoid reaching images outside image_path.
|
||||
|
Reference in New Issue
Block a user