[TYPO3-core] RFC: feature #2675
Wolfgang Klinger
wolfgang at stufenlos.net
Mon Feb 27 20:42:23 CET 2006
*hiya!*
Type: feature
Cropscale for imgResources
BT reference: http://bugs.typo3.org/view.php?id=2675
I modified and cleaned up Stefan Geith's patch, he's already written
some english documentation (I'll post it here if we get an approval).
I think the best way to demonstrate how it works would be to include an
image to the documentation section, as this percent stuff is not that
easy to understand at a first glance.
AND I had some jpg quality issues until I set the new png_truecolor
property to "1".
Please test it and give us feedback.
tia, bye
Wolfgang
-------------- next part --------------
--- TYPO3core/t3lib/class.t3lib_stdgraphic.php 2006-02-26 11:14:26.000000000 +0100
+++ TYPO3core_testing/t3lib/class.t3lib_stdgraphic.php 2006-02-27 16:18:57.000000000 +0100
@@ -2146,11 +2146,12 @@
}
$command = $this->scalecmd.' '.$info[0].'x'.$info[1].'! '.$params.' ';
+ $cropscale = ($data['crs'] ? 'crs-V'.$data['cropV'].'H'.$data['cropH'] : '');
if ($this->alternativeOutputKey) {
- $theOutputName = t3lib_div::shortMD5($command.basename($imagefile).$this->alternativeOutputKey.$frame);
+ $theOutputName = t3lib_div::shortMD5($command.$cropscale.basename($imagefile).$this->alternativeOutputKey.$frame);
} else {
- $theOutputName = t3lib_div::shortMD5($command.$imagefile.filemtime($imagefile).$frame);
+ $theOutputName = t3lib_div::shortMD5($command.$cropscale.$imagefile.filemtime($imagefile).$frame);
}
if ($this->imageMagickConvert_forceFileNameBody) {
$theOutputName = $this->imageMagickConvert_forceFileNameBody;
@@ -2164,7 +2165,31 @@
// Register temporary filename:
$GLOBALS['TEMP_IMAGES_ON_PAGE'][] = $output;
- if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output,$imagefile)) {
+ if ($data['crs']) {
+ if ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output, $imagefile)) {
+ $crsOutput = str_replace('pics/', 'pics/crs-', $output);
+ $this->imageMagickExec($imagefile.$frame, $crsOutput, $command);
+ $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
+ $gifCreator->init();
+ if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] !== 0) {
+ if (!$data['origW']) { $data['origW'] = $data[0]; }
+ if (!$data['origH']) { $data['origH'] = $data[1]; }
+ $ofX = intval(($data['origW'] - $data[0]) * ($data['cropH']+100)/200);
+ $ofY = intval(($data['origH'] - $data[1]) * ($data['cropV']+100)/200);
+ $tmpParm = Array('XY' => intval($data['origW']).','.intval($data['origH']),
+ '10' => 'IMAGE',
+ '10.' => array('file'=> $crsOutput, 'offset'=> $ofX.','.$ofY),
+ );
+ $gifCreator->start($tmpParm, array());
+ $newoutput = $gifCreator->gifBuild();
+ if (!copy($newoutput,$output)) {
+ $output = $newoutput;
+ }
+ } else {
+ $output = $crsOutput;
+ }
+ }
+ } elseif ($this->dontCheckForExistingTempFile || !$this->file_exists_typo3temp_file($output,$imagefile)) {
$this->imageMagickExec($imagefile.$frame,$output,$command);
}
if (@file_exists($output)) {
@@ -2285,6 +2310,16 @@
*/
function getImageScale($info,$w,$h,$options) {
if (strstr($w.$h, 'm')) {$max=1;} else {$max=0;}
+
+ if (strstr($w.$h, 'c')) {
+ $out['cropH'] = intval(substr(strstr($w, 'c'), 1));
+ $out['cropV'] = intval(substr(strstr($h, 'c'), 1));
+ $crs = true;
+ } else {
+ $crs = false;
+ }
+ $out['crs'] = $crs;
+
$w=intval($w);
$h=intval($h);
// if there are max-values...
@@ -2340,6 +2375,14 @@
$w = round($h*$ratio);
}
}
+ if ($crs) {
+ $ratio = $info[0] / $info[1];
+ if ($h * $ratio < $w) {
+ $h = round($w / $ratio);
+ } else {
+ $w = round($h * $ratio);
+ }
+ }
$info[0] = $w;
$info[1] = $h;
}
@@ -2348,13 +2391,13 @@
$out[1]=$info[1];
// Set minimum-measures!
if ($options['minW'] && $out[0]<$options['minW']) {
- if ($max && $out[0]) {
+ if (($max || $crs) && $out[0]) {
$out[1]= round($out[1]*$options['minW']/$out[0]);
}
$out[0]=$options['minW'];
}
if ($options['minH'] && $out[1]<$options['minH']) {
- if ($max && $out[1]) {
+ if (($max || $crs) && $out[1]) {
$out[0]= round($out[0]*$options['minH']/$out[1]);
}
$out[1]=$options['minH'];
@@ -2885,4 +2928,4 @@
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']);
}
-?>
\ No newline at end of file
+?>
More information about the TYPO3-team-core
mailing list