mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-28 09:59:54 +02:00
Added option fill-to-fit, ff. Fix #38.
This commit is contained in:
102
webroot/img.php
102
webroot/img.php
@@ -116,6 +116,23 @@ if (isset($config['default_timezone'])) {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* verbose, v - do a verbose dump of what happens
|
||||
*/
|
||||
$verbose = getDefined(array('verbose', 'v'), true, false);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create the class for the image.
|
||||
*/
|
||||
require $config['cimage_class'];
|
||||
|
||||
$img = new CImage();
|
||||
$img->setVerbose($verbose);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* shortcut, sc - extend arguments with a constant value, defined
|
||||
* in config-file.
|
||||
@@ -135,13 +152,6 @@ if (isset($shortcut)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* verbose, v - do a verbose dump of what happens
|
||||
*/
|
||||
$verbose = getDefined(array('verbose', 'v'), true, false);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* src - the source image file.
|
||||
*/
|
||||
@@ -262,6 +272,45 @@ verbose("crop to fit = $cropToFit");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set default background color from config file.
|
||||
*/
|
||||
if (isset($config['background_color'])) {
|
||||
$img->setDefaultBackgroundColor($config['background_color']);
|
||||
verbose("Using default background_color = {$config['background_color']}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* bgColor - Default background color to use
|
||||
*/
|
||||
$bgColor = get(array('bgColor', 'bgc'), null);
|
||||
|
||||
verbose("bgColor = $bgColor");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* fill-to-fit, ff - affecting the resulting image width, height and resize options
|
||||
*/
|
||||
$fillToFit = get(array('fill-to-fit', 'ff'), null);
|
||||
|
||||
verbose("fill-to-fit = $fillToFit");
|
||||
|
||||
if ($fillToFit !== null) {
|
||||
|
||||
if (!empty($fillToFit)) {
|
||||
$bgColor = $fillToFit;
|
||||
verbose("fillToFit changed bgColor to = $bgColor");
|
||||
}
|
||||
|
||||
$fillToFit = true;
|
||||
verbose("fill-to-fit (fixed) = $fillToFit");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* no-ratio, nr, stretch - affecting the resulting image width, height and resize options
|
||||
*/
|
||||
@@ -392,20 +441,6 @@ verbose("blur = $blur");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* rotate - Rotate the image with an angle, before processing
|
||||
*/
|
||||
/*
|
||||
$rotate = get(array('rotate', 'r'));
|
||||
|
||||
is_null($rotate)
|
||||
or ($rotate >= -360 and $rotate <= 360)
|
||||
or errorPage('Rotate out of range');
|
||||
|
||||
verbose("rotate = $rotate");
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* rotateBefore - Rotate the image with an angle, before processing
|
||||
*/
|
||||
@@ -432,19 +467,6 @@ verbose("rotateAfter = $rotateAfter");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* bgColor - Default background color to use
|
||||
*/
|
||||
$bgColor = hexdec(get(array('bgColor', 'bgc')));
|
||||
|
||||
is_null($bgColor)
|
||||
or ($bgColor >= 0 and $bgColor <= hexdec("FFFFFF"))
|
||||
or errorPage('Background color needs a hex value');
|
||||
|
||||
verbose("bgColor = $bgColor");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* autoRotate - Auto rotate based on EXIF information
|
||||
*/
|
||||
@@ -492,16 +514,6 @@ verbose("dpr = $dpr");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create the class for the image.
|
||||
*/
|
||||
require $config['cimage_class'];
|
||||
|
||||
$img = new CImage();
|
||||
$img->setVerbose($verbose);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* convolve - image convolution as in http://php.net/manual/en/function.imageconvolution.php
|
||||
*/
|
||||
@@ -540,7 +552,6 @@ EOD;
|
||||
/**
|
||||
* Load, process and output the image
|
||||
*/
|
||||
|
||||
$img->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||
->setSource($srcImage, $config['image_path'])
|
||||
->setOptions(
|
||||
@@ -551,6 +562,7 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||
'aspectRatio' => $aspectRatio,
|
||||
'keepRatio' => $keepRatio,
|
||||
'cropToFit' => $cropToFit,
|
||||
'fillToFit' => $fillToFit,
|
||||
'crop' => $crop,
|
||||
'area' => $area,
|
||||
|
||||
|
@@ -52,6 +52,18 @@ return array(
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set default background color for all images. Override it using
|
||||
* option bgColor.
|
||||
* Colorvalue is 6 digit hex string or 8 digit hex string if using
|
||||
* the alpha channel where 00 is opaqe and 7f is transparent.
|
||||
*
|
||||
*/
|
||||
//'background_color' => "FFFFFF",
|
||||
//'background_color' => "FFFFFF7F",
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Post processing of images using external tools, set to true or false
|
||||
* and set command to be executed.
|
||||
|
43
webroot/test/test_issue38.php
Normal file
43
webroot/test/test_issue38.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// Include config for all testcases
|
||||
include __DIR__ . "/config.php";
|
||||
|
||||
|
||||
|
||||
// The title of the test case
|
||||
$title = "Testing issue 38 - fill to fit, together with background colors";
|
||||
|
||||
|
||||
|
||||
// Provide a short description of the testcase.
|
||||
$description = "The issue was to implement fill-to-fit, but it needs some flexibility in how to choose the background color and it also affects rotation of the image (the background color does). So this testcase is both for fill-to-fit and for background color (thereby including a test using rotate).";
|
||||
|
||||
|
||||
|
||||
// Use these images in the test
|
||||
$images = array(
|
||||
'kodim04.png',
|
||||
);
|
||||
|
||||
|
||||
|
||||
// For each image, apply these testcases
|
||||
$cache = "&nc"; // ""; // "&nc"
|
||||
$testcase = array(
|
||||
"$cache&w=300&h=300&fill-to-fit",
|
||||
"$cache&w=200&h=400&fill-to-fit",
|
||||
"$cache&w=300&h=300&fill-to-fit=ff0000",
|
||||
"$cache&w=200&h=400&fill-to-fit=ff0000",
|
||||
"$cache&w=300&h=300&fill-to-fit=ff00003f",
|
||||
"$cache&w=200&h=400&fill-to-fit=ff00003f",
|
||||
"$cache&w=200&h=400&fill-to-fit&bgc=ff0000",
|
||||
"$cache&w=300&h=300&fill-to-fit&bgc=ff00003f",
|
||||
"$cache&w=300&h=300&ra=45",
|
||||
"$cache&w=300&h=300&ra=45&bgc=ff0000",
|
||||
"$cache&w=300&h=300&ra=45&bgc=ff00003f",
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Applu testcases and present results
|
||||
include __DIR__ . "/template.php";
|
Reference in New Issue
Block a user