Project

General

Profile

Bug #14537 » GIFBuilder_Truecolor_2006-01-19.diff

Administrator Admin, 2006-01-19 02:22

View differences:

TYPO3core.gifbuilder/t3lib/class.t3lib_div.php 2006-01-19 02:04:38.894817272 +0100
if($command=='composite' && $switchCompositeParameters) { // Because of some weird incompatibilities between ImageMagick 4 and 6 (plus GraphicsMagick), it is needed to change the parameters order under some preconditions
$paramsArr = t3lib_div::unQuoteFilenames($parameters);
if(count($paramsArr)==6) { // The mask image has been specified => swap the parameters
$tmp = $paramsArr[3];
$paramsArr[3] = $paramsArr[2];
$paramsArr[2] = $tmp;
if(count($paramsArr)>5) { // The mask image has been specified => swap the parameters
$tmp = $paramsArr[count($paramsArr)-3];
$paramsArr[count($paramsArr)-3] = $paramsArr[count($paramsArr)-4];
$paramsArr[count($paramsArr)-4] = $tmp;
}
$cmdLine = $path.' '.implode(' ', $paramsArr);
TYPO3core.gifbuilder/t3lib/class.t3lib_stdgraphic.php 2006-01-19 00:49:59.560742264 +0100
var $GD2=0; // Set, if the GDlib used is version 2.
var $imagecopyresized_fix=0; // If set, imagecopyresized will not be called directly. For GD2 (some PHP installs?)
var $gifExtension = 'gif'; // This should be changed to 'png' if you want this class to read/make PNG-files instead!
var $gdlibExtensions = ''; // File formats supported by gdlib. This variable get's filled in "init" method
var $truecolor = false; // Set to false if we shall generate images which get reduced in color
var $truecolorColors = 0xffffff; // 16777216 Colors is the maximum value for PNG, JPEG truecolor images (24-bit, 8-bit / Channel)
var $TTFLocaleConv = ''; // Used to recode input to TTF-functions for other charsets.
var $enable_typo3temp_db_tracking = 0; // If set, then all files in typo3temp will be logged in a database table. In addition to being a log of the files with original filenames, it also serves to secure that the same image is not rendered simultaneously by two different processes.
var $imageFileExt = 'gif,jpg,jpeg,png,tif,bmp,tga,pcx,ai,pdf'; // Commalist of file extensions perceived as images by TYPO3. List should be set to 'gif,png,jpeg,jpg' if IM is not available. Lowercase and no spaces between!
......
);
var $NO_IMAGE_MAGICK = '';
var $V5_EFFECTS = 0;
var $im_version_4 = 0;
var $mayScaleUp = 1;
// Variables for testing, alternative usage etc.
......
function init() {
$gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
if (function_exists('imagecreatefromjpeg')&&function_exists('imagejpeg')) {
$this->gdlibExtensions .= ',jpg,jpeg';
}
if (function_exists('imagecreatefrompng')&&function_exists('imagepng')) {
$this->gdlibExtensions .= ',png';
}
if (function_exists('imagecreatefromgif')&&function_exists('imagegif')) {
$this->gdlibExtensions .= ',gif';
}
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['truecolor']) {
$this->truecolor = true;
}
if (!function_exists('imagecreatetruecolor')) {
$this->truecolor = false;
}
if (!$gfxConf['im_version_5']) {
$this->im_version_4 = true;
}
// When GIFBUILDER gets used in truecolor mode (GD2 required)
if ($this->truecolor) {
$this->cmds['png'] = ''; // No colors parameter if we generate truecolor images.
$this->cmds['gif'] = ''; // No colors parameter if we generate truecolor images.
}
// Setting default JPG parameters:
$this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -sharpen 50 -quality '.intval($gfxConf['im_jpg_quality']);
$this->jpegQuality = t3lib_div::intInRange($gfxConf['jpg_quality'], 10, 100, 75);
$this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -sharpen 50 -quality '.$this->jpegQuality;
if ($gfxConf['im_combine_filename']) $this->combineScript=$gfxConf['im_combine_filename'];
if ($gfxConf['im_noFramePrepended']) $this->noFramePrepended=1;
......
// - therefore must be disabled in order not to perform sharpen, blurring and such.
$this->NO_IM_EFFECTS = 1;
$this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality '.intval($gfxConf['im_jpg_quality']);
$this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace RGB -quality '.$this->jpegQuality;
}
// ... but if 'im_v5effects' is set, dont care about 'im_no_effects'
if ($gfxConf['im_v5effects']) {
......
*/
function maskImageOntoImage(&$im,$conf,$workArea) {
if ($conf['file'] && $conf['mask']) {
$BBimage = $this->imageMagickConvert($conf['file'],$this->gifExtension,'','','','','');
$BBmask = $this->imageMagickConvert($conf['mask'],$this->gifExtension,'','','','','');
$imgInf = pathinfo($conf['file']);
$imgExt = strtolower($imgInf['extension']);
if (!t3lib_div::inList($this->gdlibExtensions, $imgExt)) {
$BBimage = $this->imageMagickConvert($conf['file'],$this->gifExtension,'','','','','');
} else {
$BBimage = $this->getImageDimensions($conf['file']);
}
$maskInf = pathinfo($conf['mask']);
$maskExt = strtolower($maskInf['extension']);
if (!t3lib_div::inList($this->gdlibExtensions, $maskExt)) {
$BBmask = $this->imageMagickConvert($conf['mask'],$this->gifExtension,'','','','','');
} else {
$BBmask = $this->getImageDimensions($conf['mask']);
}
if ($BBimage && $BBmask) {
$w = imagesx($im);
$h = imagesy($im);
......
$theMask2 = $tmpStr.'_mask2.'.trim($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_noloss']);
// prepare overlay image
$cpImg = $this->imageCreateFromFile($BBimage[3]);
$destImg = imagecreate($w,$h);
ImageColorAllocate($destImg, 0,0,0);
$destImg = $this->imagecreate($w,$h);
$Bcolor = ImageColorAllocate($destImg, 0,0,0);
ImageFilledRectangle($destImg, 0, 0, $w, $h, $Bcolor);
$this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
$this->ImageGif($destImg, $theImage);
$this->ImageWrite($destImg, $theImage);
imageDestroy($cpImg);
imageDestroy($destImg);
// prepare mask image
$cpImg = $this->imageCreateFromFile($BBmask[3]);
$destImg = imagecreate($w,$h);
ImageColorAllocate($destImg, 0,0,0);
$destImg = $this->imagecreate($w,$h);
$Bcolor = ImageColorAllocate($destImg, 0, 0, 0);
ImageFilledRectangle($destImg, 0, 0, $w, $h, $Bcolor);
$this->copyGifOntoGif($destImg,$cpImg,$conf,$workArea);
$this->ImageGif($destImg, $theMask);
$this->ImageWrite($destImg, $theMask);
imageDestroy($cpImg);
imageDestroy($destImg);
// treat the mask
$this->imageMagickExec($theMask,$theMask2,'-colorspace GRAY'.$this->maskNegate);
// mask the images
$this->ImageGif($im, $theDest);
$this->ImageWrite($im, $theDest);
$this->combineExec($theDest,$theImage,$theMask2,$theDest);
$this->combineExec($theDest,$theImage,$theMask,$theDest, true); // Let combineExec handle maskNegation
$backIm = $this->imageCreateFromFile($theDest); // The main image is loaded again...
if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
......
unlink($theDest);
unlink($theImage);
unlink($theMask);
unlink($theMask2);
}
}
}
......
*/
function copyImageOntoImage(&$im,$conf,$workArea) {
if ($conf['file']) {
if ($conf['BBOX'][2]!=$this->gifExtension) {
if (!t3lib_div::inList($this->gdlibExtensions, $conf['BBOX'][2])) {
$conf['BBOX']=$this->imageMagickConvert($conf['BBOX'][3],$this->gifExtension,'','','','','');
$conf['file']=$conf['BBOX'][3];
}
......
$tile[0] = t3lib_div::intInRange($tile[0],1,20);
$tile[1] = t3lib_div::intInRange($tile[1],1,20);
$cpOff = $this->objPosition($conf,$workArea,Array($cpW*$tile[0],$cpH*$tile[1]));
for ($xt=0;$xt<$tile[0];$xt++) {
$Xstart=$cpOff[0]+$cpW*$xt;
if ($Xstart+$cpW > $workArea[0]) { // if this image is inside of the workArea, then go on
......
*/
function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) {
if ($this->imagecopyresized_fix) {
$im_base = imagecreatetruecolor(imagesx($im), imagesy($im)); // Make true color image
$im_base = $this->imagecreate(imagesx($im), imagesy($im)); // Make true color image
imagecopyresized($im_base, $im, 0,0,0,0, imagesx($im),imagesy($im),imagesx($im),imagesy($im)); // Copy the source image onto that
imagecopyresized($im_base, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h); // Then copy the $cpImg onto that (the actual operation!)
$im = $im_base; // Set pointer
$this->makeEffect($im, Array('value'=>'colors=256')); // Reduce colors to 256 - make SURE that IM is working then!
if (!$this->truecolor) {
$this->makeEffect($im, Array('value'=>'colors='.t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256))); // Reduce to "reduceColors" colors - make SURE that IM is working then!
}
} else {
imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
}
......
/********************************
*
* Text / "TEXT" GIFBUILDER object
......
// NiceText is calculated
if (!$conf['niceText']) {
// Font Color is reserved:
$this->reduceColors($im,256, 200);
if (!$this->truecolor) {
$reduce = t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256);
$this->reduceColors($im, $reduce-49, $reduce-50); // If "reduce-49" colors (or more) are used reduce them to "reduce-50"
}
$Fcolor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
// antiAliasing is setup:
$Fcolor = ($conf['antiAlias']) ? $Fcolor : -$Fcolor;
......
$newH = ceil($sF*imagesy($im));
// Make mask
$maskImg = imagecreate($newW, $newH);
ImageColorAllocate($maskImg, 255,255,255);
$maskImg = $this->imagecreate($newW, $newH);
$Bcolor = ImageColorAllocate($maskImg, 255,255,255);
ImageFilledRectangle($maskImg, 0, 0, $newW, $newH, $Bcolor);
$Fcolor = ImageColorAllocate($maskImg, 0,0,0);
if ($spacing || $wordSpacing) { // If any kind of spacing applys, we use this function:
$this->SpacedImageTTFText($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, t3lib_stdGraphic::prependAbsolutePath($conf['fontFile']), $theText, $spacing, $wordSpacing, $conf['splitRendering.'],$sF);
} else {
$this->ImageTTFTextWrapper($maskImg, $conf['fontSize'], $conf['angle'], $txtPos[0], $txtPos[1], $Fcolor, $conf['fontFile'], $theText, $conf['splitRendering.'],$sF);
}
$this->ImageGif($maskImg, $fileMask);
$this->ImageWrite($maskImg, $fileMask);
ImageDestroy($maskImg);
// Downscales the mask
......
}
}
}
$this->imageMagickExec($fileMask,$fileMask,$command);
// Make the color-file
$colorImg = imagecreate($w,$h);
ImageColorAllocate($colorImg, $cols[0],$cols[1],$cols[2]);
$this->ImageGif($colorImg, $fileColor);
$colorImg = $this->imagecreate($w,$h);
$Ccolor = ImageColorAllocate($colorImg, $cols[0],$cols[1],$cols[2]);
ImageFilledRectangle($colorImg, 0, 0, $w, $h, $Ccolor);
$this->ImageWrite($colorImg, $fileColor);
ImageDestroy($colorImg);
// The mask is applied
$this->ImageGif($im, $fileMenu); // The main pictures is saved temporarily
$this->combineExec($fileMenu,$fileColor,$fileMask,$fileMenu);
$this->ImageWrite($im, $fileMenu); // The main pictures is saved temporarily
$this->combineExec($fileMenu,$fileColor,$fileMask, $fileMenu);
$backIm = $this->imageCreateFromFile($fileMenu); // The main image is loaded again...
if ($backIm) { // ... and if nothing went wrong we load it onto the old one.
ImageColorTransparent($backIm,-1);
......
$fileMask = $tmpStr.'_mask.'.$this->gifExtension;
// BlurColor Image laves
$blurColImg = imagecreate($w,$h);
$blurColImg = $this->imagecreate($w,$h);
$bcols=$this->convertColor($conf['color']);
ImageColorAllocate($blurColImg, $bcols[0],$bcols[1],$bcols[2]);
$this->ImageGif($blurColImg, $fileColor);
$Bcolor = ImageColorAllocate($blurColImg, $bcols[0],$bcols[1],$bcols[2]);
ImageFilledRectangle($blurColImg, 0, 0, $w, $h, $Bcolor);
$this->ImageWrite($blurColImg, $fileColor);
ImageDestroy($blurColImg);
// The mask is made: BlurTextImage
$blurTextImg = imagecreate($w+$blurBorder*2,$h+$blurBorder*2);
ImageColorAllocate($blurTextImg, 0,0,0); // black background
$blurTextImg = $this->imagecreate($w+$blurBorder*2,$h+$blurBorder*2);
$Bcolor = ImageColorAllocate($blurTextImg, 0,0,0); // black background
ImageFilledRectangle($blurTextImg, 0, 0, $w+$blurBorder*2, $h+$blurBorder*2, $Bcolor);
$txtConf['fontColor'] = 'white';
$blurBordArr = Array($blurBorder,$blurBorder);
$this->makeText($blurTextImg,$txtConf, $this->applyOffset($workArea,$blurBordArr));
$this->ImageGif($blurTextImg, $fileMask); // dump to temporary file
$this->ImageWrite($blurTextImg, $fileMask); // dump to temporary file
ImageDestroy($blurTextImg); // destroy
......
}
}
$this->imageMagickExec($fileMask,$fileMask,$command);
$this->imageMagickExec($fileMask,$fileMask,$command.' +matte');
$blurTextImg_tmp = $this->imageCreateFromFile($fileMask); // the mask is loaded again
if ($blurTextImg_tmp) { // if nothing went wrong we continue with the blurred mask
// cropping the border from the mask
$blurTextImg = imagecreate($w,$h);
$blurTextImg = $this->imagecreate($w,$h);
$this->imagecopyresized($blurTextImg, $blurTextImg_tmp, 0, 0, $blurBorder, $blurBorder, $w, $h, $w, $h);
ImageDestroy($blurTextImg_tmp); // Destroy the temporary mask
......
$this->outputLevels($blurTextImg,0,$high,$this->maskNegate); // reducing levels as the opacity demands
}
$this->ImageGif($blurTextImg, $fileMask); // Dump the mask again
$this->ImageWrite($blurTextImg, $fileMask); // Dump the mask again
ImageDestroy($blurTextImg); // Destroy the mask
// The pictures are combined
$this->ImageGif($im, $fileMenu); // The main pictures is saved temporarily
$this->ImageWrite($im, $fileMenu); // The main pictures is saved temporarily
$this->combineExec($fileMenu,$fileColor,$fileMask,$fileMenu);
......
$conf['offset']=$cords[0].','.$cords[1];
$cords = $this->objPosition($conf,$workArea,Array($cords[2],$cords[3]));
$cols=$this->convertColor($conf['color']);
$this->reduceColors($im,256, 255);
if (!$this->truecolor) {
$reduce = t3lib_div::intInRange($this->setup['reduceColors'], 256, $this->truecolorColors, 256);
$this->reduceColors($im, $reduce-1, $reduce-2); // If "reduce-1" colors (or more) are used reduce them to "reduce-2"
}
$tmpColor = ImageColorAllocate($im, $cols[0],$cols[1],$cols[2]);
imagefilledrectangle($im, $cords[0], $cords[1], $cords[0]+$cords[2]-1, $cords[1]+$cords[3]-1, $tmpColor);
}
......
$conf['offset']=$cords[0].','.$cords[1];
$cords = $this->objPosition($conf,$this->workArea,Array($cords[2],$cords[3]));
$newIm = imagecreate($cords[2],$cords[3]);
$newIm = $this->imagecreate($cords[2],$cords[3]);
$cols=$this->convertColor($conf['backColor']?$conf['backColor']:$this->setup['backColor']);
ImageColorAllocate($newIm, $cols[0],$cols[1],$cols[2]);
$Bcolor = ImageColorAllocate($newIm, $cols[0],$cols[1],$cols[2]);
ImageFilledRectangle($newIm, 0, 0, $cords[2], $cords[3], $Bcolor);
$newConf = Array();
$workArea = Array(0,0,$cords[2],$cords[3]);
......
if ($conf['width'] || $conf['height'] || $conf['params']) {
$tmpStr = $this->randomName();
$theFile = $tmpStr.'.'.$this->gifExtension;
$this->ImageGif($im, $theFile);
$this->ImageWrite($im, $theFile);
$theNewFile = $this->imageMagickConvert($theFile,$this->gifExtension,$conf['width'],$conf['height'],$conf['params'],'','');
$tmpImg = $this->imageCreateFromFile($theNewFile[3]);
if ($tmpImg) {
......
}
/**
* Reduce colors in image
* Reduce colors in image dependend on the actual amount of colors (Only works if we are not in truecolor mode)
*
* @param integer GDlib Image Pointer
* @param integer The max number of colors in the image before a reduction will happen; basically this means that IF the GD image current has the same amount or more colors than $limit define, THEN a reduction is performed.
......
* @return void
*/
function reduceColors(&$im,$limit, $cols) {
if (ImageColorsTotal($im)>=$limit) {
if (!$this->truecolor && ImageColorsTotal($im)>=$limit) {
$this->makeEffect($im, Array('value'=>'colors='.$cols) );
}
}
/**
* Reduce colors in image using IM and create a palette based image if possible (<=256 colors)
*
* @param string Image file to reduce
* @param integer Number of colors to reduce the image to.
* @return string Reduced file
*/
function IMreduceColors($file, $cols) {
$fI = t3lib_div::split_fileref($file);
$ext = strtolower($fI['fileext']);
$result = $this->randomName().'.'.$ext;
if (($reduce = t3lib_div::intInRange($cols, 0, ($ext=='gif'?256:$this->truecolorColors), 0))>0) {
$params = ' -colors '.$reduce;
if (!$this->im_version_4) {
// IM4 doesn't have this options but forces them automatically if applicaple (<256 colors in image)
if ($reduce<=256) { $params .= ' -type Palette'; }
if ($ext=='png' && $reduce<=256) { $prefix = 'png8:'; }
}
$this->imageMagickExec($file, $prefix.$result, $params);
return $result;
}
// Nothing to perform
return $file;
}
......
* @param string The relative (to PATH_site) image filepath, output filename (written to)
* @return void
*/
function combineExec($input,$overlay,$mask,$output) {
function combineExec($input,$overlay,$mask,$output, $handleNegation = false) {
if (!$this->NO_IMAGE_MAGICK) {
$cmd = t3lib_div::imageMagickCommand('combine', '-compose over '.$this->wrapFileName($input).' '.$this->wrapFileName($overlay).' '.$this->wrapFileName($mask).' '.$this->wrapFileName($output));
$params = '-colorspace GRAY +matte';
if ($handleNegation) {
if ($this->maskNegate) {
$params .= ' '.$this->maskNegate;
}
}
$theMask = $this->randomName().'.'.$this->gifExtension;
$this->imageMagickExec($mask, $theMask, $params);
$cmd = t3lib_div::imageMagickCommand('combine', '-compose over +matte '.$this->wrapFileName($input).' '.$this->wrapFileName($overlay).' '.$this->wrapFileName($theMask).' '.$this->wrapFileName($output)); // +matte = no alpha layer in output
$this->IM_commands[] = Array ($output,$cmd);
$ret = exec($cmd);
......
function applyImageMagickToPHPGif(&$im, $command) {
$tmpStr = $this->randomName();
$theFile = $tmpStr.'.'.$this->gifExtension;
$this->ImageGif($im, $theFile);
$this->ImageWrite($im, $theFile);
$this->imageMagickExec($theFile,$theFile,$command);
$tmpImg = $this->imageCreateFromFile($theFile);
if ($tmpImg) {
......
ereg('([^\.]*)$',$file,$reg);
$ext=strtolower($reg[0]);
switch($ext) {
case $this->gifExtension:
if ($this->ImageGif($this->im, $file)) {
// ImageMagick operations
if($this->setup['reduceColors']) {
$this->imageMagickExec($file,$file,' -colors '.t3lib_div::intInRange($this->setup['reduceColors'],2,255));
t3lib_div::gif_compress($file,''); // Compress with IM (lzw) or GD (rle) (Workaround for the absence of lzw-compression in GD)
} else {
t3lib_div::gif_compress($file, 'IM'); // Compress with IM! (adds extra compression, LZW from ImageMagick) (Workaround for the absence of lzw-compression in GD)
case 'gif':
case 'png':
if ($this->ImageWrite($this->im, $file)) {
// ImageMagick operations
if ($this->setup['reduceColors']) {
$reduced = $this->IMreduceColors($file, $this->setup['reduceColors']);
unlink($file);
copy($reduced, $file);
}
t3lib_div::gif_compress($file, 'IM'); // Compress with IM! (adds extra compression, LZW from ImageMagick) (Workaround for the absence of lzw-compression in GD)
}
break;
case 'jpg':
case 'jpeg':
$tmpStr = $this->randomName();
$theFile = $tmpStr.'.'.$this->gifExtension;
if ($this->ImageGif($this->im, $theFile)) {
// ImageMagick operations
$operations='';
if($this->setup['quality']) {
$operations.=' -quality '.t3lib_div::intInRange($this->setup['quality'],10,100);
}
$this->imageMagickExec($theFile,$file,$operations);
if (!$this->dontUnlinkTempFiles) {
unlink($theFile);
}
$quality = 0; // Use the default
if($this->setup['quality']) {
$quality = t3lib_div::intInRange($this->setup['quality'],10,100);
}
if ($this->ImageWrite($this->im, $file, $quality));
break;
}
$GLOBALS['TEMP_IMAGES_ON_PAGE'][]=$file;
......
*
* @param pointer The GDlib image resource pointer
* @param string The filename to write to
* @return mixed The output of either imageGif or imagePng based on whether the $this->gifExtension was set to "gif" or "png"
* @return mixed The output of either imageGif, imagePng or imageJpeg based on the filename to write
* @see maskImageOntoImage(), scale(), output()
*/
function ImageGif($destImg, $theImage) {
function ImageWrite($destImg, $theImage) {
imageinterlace ($destImg,0);
if ($this->gifExtension=='gif') {
return ImageGif($destImg, $theImage);
}
if ($this->gifExtension=='png') {
return ImagePng($destImg, $theImage);
}
$ext = strtolower(substr($theImage, strrpos($theImage, '.')+1));
switch ($ext) {
case 'jpg':
case 'jpeg':
if (!$quality) {
$quality = $this->jpegQuality;
}
if (function_exists('imageJpeg')) {
return imageJpeg($destImg, $theImage, $quality);
}
break;
case 'gif':
if (function_exists('imageGif')) {
return imageGif($destImg, $theImage);
}
break;
case 'png':
if (function_exists('imagePng')) {
return ImagePng($destImg, $theImage);
}
break;
}
return false; // Extension invalid or write-function does not exist
}
/**
* Writes the input GDlib image pointer to file. Now just a wrapper to ImageWrite.
*
* @param pointer The GDlib image resource pointer
* @param string The filename to write to
* @return mixed The output of either imageGif, imagePng or imageJpeg based on the filename to write
* @see imageWrite()
* @deprecated
*/
function imageGif($destImg, $theImage) {
return $this->imageWrite($destImg, $theImage);
}
/**
......
* Creates a new GDlib image resource based on the input image filename.
* If it fails creating a image from the input file a blank gray image with the dimensions of the input image will be created instead.
*
* @param string Image filename
* @param string Image filename
* @return pointer Image Resource pointer
*/
function imageCreateFromFile($sourceImg) {
$imgInf = pathinfo($sourceImg);
$ext = strtolower($imgInf['extension']);
if ($ext=='gif' && function_exists('imagecreatefromgif')) {
return imageCreateFromGif($sourceImg);
} elseif ($ext=='png' && function_exists('imagecreatefrompng')) {
return imageCreateFromPng($sourceImg);
} elseif (($ext=='jpg' || $ext=='jpeg') && function_exists('imagecreatefromjpeg')) {
return imageCreateFromJpeg($sourceImg);
switch ($ext) {
case 'gif':
if (function_exists('imagecreatefromgif')) {
return imageCreateFromGif($sourceImg);
}
break;
case 'png':
if (function_exists('imagecreatefrompng')) {
return imageCreateFromPng($sourceImg);
}
break;
case 'jpg':
case 'jpeg':
if (function_exists('imagecreatefromjpeg')) {
return imageCreateFromJpeg($sourceImg);
}
break;
}
// If non of the above:
$i = @getimagesize($sourceImg);
$im = imagecreate($i[0],$i[1]);
ImageColorAllocate($im, 128,128,128);
$im = $this->imagecreate($i[0],$i[1]);
$Bcolor = ImageColorAllocate($im, 128,128,128);
ImageFilledRectangle($im, 0, 0, $i[0], $i[1], $Bcolor);
return $im;
}
/**
* Creates a new GD image resource. Wrapper for imagecreate(truecolor) depended if GD2 is used.
*
* @param integer Width
* @param integer Height
* @return pointer Image Resource pointer
*/
function imagecreate($w, $h) {
if($this->truecolor && $this->GD2 && function_exists('imagecreatetruecolor')) {
return imagecreatetruecolor($w, $h);
} else {
return imagecreate($w, $h);
}
}
/**
* Returns the HEX color value for an RGB color array
*
* @param array RGB color array
* @return string HEX color value
*/
function hexColor($col) {
$r = dechex($col[0]);
if (strlen($r)<2) { $r = '0'.$r; }
$g = dechex($col[1]);
if (strlen($g)<2) { $g = '0'.$g; }
$b = dechex($col[2]);
if (strlen($b)<2) { $b = '0'.$b; }
return '#'.$r.$g.$b;
}
/**
* Unifies all colors given in the colArr color array to the first color in the array.
*
* @param pointer Image resource
* @param array array containing RGB color arrays
* @return integer The index of the unified color
*/
function unifyColors(&$img, $colArr) {
$retCol = false;
if (is_array($colArr)&&function_exists('imagepng')&&function_exists('imagecreatefrompng')) {
$origName = $preName = $this->randomName().'.png';
$postName = $this->randomName().'.'.trim($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_noloss']);
$this->imageWrite($img, $preName);
$firstCol = array_shift($colArr);
$firstColArr = $this->convertColor($firstCol);
$firstCol = $this->hexColor($firstColArr);
while(list(,$transparentColor)=each($colArr)) {
$transparentColor = $this->convertColor($transparentColor);
$transparentColor = $this->hexColor($transparentColor);
$cmd = '-fill "'.$firstCol.'" -opaque "'.$transparentColor.'"';
$this->imageMagickExec($preName, $postName, $cmd);
$preName = $postName;
}
$this->imageMagickExec($postName, $origName, '');
if (@is_file($origName)) {
$tmpImg = $this->imageCreateFromFile($origName);
if ($tmpImg) {
$img = $tmpImg;
$retCol = ImageColorExact ($img, $firstColArr[0], $firstColArr[1], $firstColArr[2]);
}
}
// unlink files from process
if (!$this->dontUnlinkTempFiles) {
unlink($origName);
unlink($postName);
}
}
return $retCol;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']) {
TYPO3core.gifbuilder/t3lib/config_default.php 2006-01-19 02:19:09.650442296 +0100
'im_noScaleUp' => 0, // Boolean. If set, images are not being scaled up if told so (in t3lib/stdgraphics.php)
'im_combine_filename' => 'combine', // String. Latest ImageMagick versions has changed the name of combine to composite. Configure here if needed.
'im_noFramePrepended' => 0, // Boolean. If set, the [x] frame indicator is NOT prepended to filenames in stdgraphic. Some IM5+ version didn't work at all with the typical [0]-prefix, which allow multipage pdf's and animated gif's to be scaled only for the first frame/page and that seriously cuts down rendering time. Set this flag only if your ImageMagick version cannot find the files. Notice that changing this flag causes temporary filenames to change, thus the server will begin scaling images again which were previously cached.
'im_jpg_quality' => 70, // Integer. Default JPEG generation quality
'jpg_quality' => 70, // Integer. Default JPEG generation quality
'enable_typo3temp_db_tracking' => 0, // Boolean. If set, then all files in typo3temp will be logged in a database table. In addition to being a log of the files with original filenames, it also serves to secure that the same image is not rendered simultaneously by two different processes.
'TTFLocaleConv' => '', // String. Enter locale conversion string used to recode input to TrueType functions. Eg. 'cp1250..UTF-8'. Works ONLY if 'recode' is enabled in PHP. Deprecated from ver. 3.6.0 of TYPO3. Set up [BE][forceCharset] as strings are automatically converted from databsae charset to UTF-8.
'TTFdpi' => '72', // Integer. Enter how many dpi the FreeType module uses. Freetype1 should be set to 72. Freetype2 should be set to 96 (otherwise fonts are rendered way bigger than FreeType1). This works as a global scaling factor for Freetype.
'truecolor' => 0, // Boolean. If truecolor png/jpgs should get created. If you use GDlib2 you can create truecolor images if they look not well currently. Note that this results in an increased image size.
),
'SYS' => Array( // System related concerning both frontend and backend.
'sitename' => 'TYPO3', // Name of the base-site. This title shows up in the root of the tree structure if you're an 'admin' backend user.
......
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif'] = 1;
}
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']==='gm') {
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 1;
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 0;
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 0;
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'] = -1;
}
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState']) {
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask']=$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask']?0:1;
}
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_jpg_quality']) {
$GLOBALS['TYPO3_CONF_VARS']['GFX']['jpg_quality'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_jpg_quality'];
}
// simple debug function which prints output immediately
function xdebug($var='',$br=0) {
TYPO3core.gifbuilder/typo3/sysext/cms/tslib/class.tslib_content.php 2006-01-18 20:22:50.471571488 +0100
if (is_array($maskArray) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
// Filename:
$fI = t3lib_div::split_fileref($theImage);
$dest = $gifCreator->tempPath.$hash.'.'.($fI['fileext']==$gifCreator->gifExtension ? $gifCreator->gifExtension : 'jpg');
$dest = $gifCreator->tempPath.$hash.'.'.(strtolower($fI['fileext'])==$gifCreator->gifExtension ? $gifCreator->gifExtension : 'jpg');
if (!@file_exists($dest)) { // Generate!
$m_mask= $maskImages['m_mask'];
$m_bgImg = $maskImages['m_bgImg'];
......
}
}
// Finish off
if ($fileArray['reduceColors']&&is_file($dest)) {
$reduced = $gifCreator->IMreduceColors($dest, $fileArray['reduceColors']);
if (is_file($reduced)) {
unlink($dest);
rename($reduced, $dest);
}
}
$GLOBALS['TSFE']->tmpl->fileCache[$hash]= $gifCreator->getImageDimensions($dest);
} else { // Normal situation:
$GLOBALS['TSFE']->tmpl->fileCache[$hash]= $gifCreator->imageMagickConvert($theImage,$fileArray['ext'],$fileArray['width'],$fileArray['height'],$fileArray['params'],$fileArray['frame'],$options);
if ($fileArray['reduceColors']&&is_file($GLOBALS['TSFE']->tmpl->fileCache[$hash][3])) {
$reduced = $gifCreator->IMreduceColors($GLOBALS['TSFE']->tmpl->fileCache[$hash][3], $fileArray['reduceColors']);
if (is_file($reduced)) {
unlink($GLOBALS['TSFE']->tmpl->fileCache[$hash][3]);
rename($reduced, $GLOBALS['TSFE']->tmpl->fileCache[$hash][3]);
}
}
}
$GLOBALS['TSFE']->tmpl->fileCache[$hash]['origFile'] = $theImage;
$GLOBALS['TSFE']->tmpl->fileCache[$hash]['origFile_mtime'] = @filemtime($theImage); // This is needed by tslib_gifbuilder, ln 100ff in order for the setup-array to create a unique filename hash.
......
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_content.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_content.php']);
}
?>
?>
TYPO3core.gifbuilder/typo3/sysext/cms/tslib/class.tslib_gifbuilder.php 2006-01-18 20:22:50.472571336 +0100
$this->setup = $conf;
$this->data = $data;
/* Hook preprocess gifbuilder conf
* Added by Julle for 3.8.0
*
......
$cObj->start($this->data);
$this->setup['backColor'] = trim($cObj->stdWrap($this->setup['backColor'], $this->setup['backColor.']));
}
if (!$this->setup['backColor']) {$this->setup['backColor']='white';}
if (!$this->setup['backColor']) { $this->setup['backColor']='white'; }
// Transparent GIFs
// not working with reduceColors
// there's an option for IM: -transparent colors
......
$XY = $this->XY;
// Gif-start
$this->im = imagecreate($XY[0],$XY[1]);
$this->im = $this->imagecreate($XY[0],$XY[1]);
$this->w = $XY[0];
$this->h = $XY[1];
// backColor is set
$cols=$this->convertColor($this->setup['backColor']);
ImageColorAllocate($this->im, $cols[0],$cols[1],$cols[2]);
$BGcols = $this->convertColor($this->setup['backColor']);
$Bcolor = ImageColorAllocate($this->im, $BGcols[0],$BGcols[1],$BGcols[2]);
ImageFilledRectangle($this->im, 0, 0, $XY[0], $XY[1], $Bcolor);
// Traverse the GIFBUILDER objects an render each one:
if (is_array($this->setup)) {
......
}
}
}
// Auto transparent background is set
if ($this->setup['transparentBackground']) {
imagecolortransparent($this->im, imagecolorat($this->im, 0, 0));
}
// TransparentColors are set
if (is_array($this->setup['transparentColor_array'])) {
reset($this->setup['transparentColor_array']);
while(list(,$transparentColor)=each($this->setup['transparentColor_array'])) {
$cols=$this->convertColor($transparentColor);
if ($this->setup['transparentColor.']['closest']) {
$colIndex = ImageColorClosest ($this->im, $cols[0],$cols[1],$cols[2]);
} else {
$colIndex = ImageColorExact ($this->im, $cols[0],$cols[1],$cols[2]);
}
if ($colIndex > -1) {
ImageColorTransparent($this->im, $colIndex);
} else {
ImageColorTransparent($this->im, ImageColorAllocate($this->im, $cols[0],$cols[1],$cols[2]));
}
break; // Originally we thought of letting many colors be defined as transparent, but GDlib seems to accept only one definition. Therefore we break here. Maybe in the future this 'break' will be cancelled if a method of truly defining many transparent colors could be found.
// Auto transparent background is set
imagecolortransparent($this->im, $Bcolor);
} elseif (is_array($this->setup['transparentColor_array'])) {
// Multiple transparent colors are set. This is done via the trick that all transparent colors get converted to one color and then this one gets set as transparent as png/gif can just have one transparent color.
$Tcolor = $this->unifyColors($this->im, $this->setup['transparentColor_array']);
if ($Tcolor) {
imagecolortransparent($this->im, $Tcolor);
}
}
}
TYPO3core.gifbuilder/typo3/sysext/install/mod/class.tx_install.php 2006-01-19 00:39:47.648767024 +0100
if (!@is_file($overlay)) die("Error: ".$overlay." was not a file");
if (!@is_file($mask)) die("Error: ".$mask." was not a file");
if ($imageProc->maskNegate) {
$outmask = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5($imageProc->alternativeOutputKey."mask").".gif";
$imageProc->imageMagickExec($mask, $outmask, '-negate');
$mask = $outmask;
}
$output = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5($imageProc->alternativeOutputKey."combine1").".jpg";
$imageProc->combineExec($input,$overlay,$mask,$output);
$imageProc->combineExec($input,$overlay,$mask,$output, true);
$fileInfo = $imageProc->getImageDimensions($output);
$result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
$this->message($headCode,"Combine using a GIF mask with only black and white",$result[0],$result[1]);
......
if (!@is_file($overlay)) die("Error: ".$overlay." was not a file");
if (!@is_file($mask)) die("Error: ".$mask." was not a file");
if ($imageProc->maskNegate) {
$outmask = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5($imageProc->alternativeOutputKey."mask2").".gif";
$imageProc->imageMagickExec($mask, $outmask, '-negate');
$mask = $outmask;
}
$output = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5($imageProc->alternativeOutputKey."combine2").".jpg";
$imageProc->combineExec($input,$overlay,$mask,$output);
$imageProc->combineExec($input,$overlay,$mask,$output, true);
$fileInfo = $imageProc->getImageDimensions($output);
$result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
$this->message($headCode,"Combine using a JPG mask with graylevels",$result[0],$result[1]);
......
if ($gdActive) {
// GD with box
$imageProc->IM_commands=array();
$im = imageCreate(170,136);
ImageColorAllocate ($im, 0, 0, 0);
$im = $imageProc->imageCreate(170,136);
$Bcolor = ImageColorAllocate ($im, 0, 0, 0);
ImageFilledRectangle($im, 0, 0, 170, 136, $Bcolor);
$workArea=array(0,0,170,136);
$conf=array(
"dimensions" => "10,50,150,36",
......
);
$imageProc->makeBox($im,$conf,$workArea);
$output = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5("GDbox").".".$imageProc->gifExtension;
$imageProc->ImageGif ($im,$output);
$imageProc->ImageWrite($im,$output);
$fileInfo = $imageProc->getImageDimensions($output);
$result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
$this->message($headCode,"Create simple image",$result[0],$result[1]);
......
$conf["color"]="olive";
$imageProc->makeBox($im,$conf,$workArea);
$output = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5("GDfromImage+box").".".$imageProc->gifExtension;
$imageProc->ImageGif ($im,$output);
$imageProc->ImageWrite($im,$output);
$fileInfo = $imageProc->getImageDimensions($output);
$GDWithBox_filesize = @filesize($output);
$result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
......
// GD with text
$imageProc->IM_commands=array();
$im = imageCreate(170,136);
ImageColorAllocate ($im, 128,128,150);
$im = $imageProc->imageCreate(170,136);
$Bcolor = ImageColorAllocate ($im, 128,128,150);
ImageFilledRectangle($im, 0, 0, 170, 136, $Bcolor);
$workArea=array(0,0,170,136);
$conf=array(
"iterations" => 1,
......
$imageProc->makeText($im,$conf,$workArea);
$output = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5("GDwithText").".".$imageProc->gifExtension;
$imageProc->ImageGif ($im,$output);
$imageProc->ImageWrite($im,$output);
$fileInfo = $imageProc->getImageDimensions($output);
$result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
$this->message($headCode,"Render text with TrueType font",$result[0],$result[1]);
......
$imageProc->makeText($im,$conf,$workArea);
$output = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5("GDwithText-niceText").".".$imageProc->gifExtension;
$imageProc->ImageGif ($im,$output);
$imageProc->ImageWrite($im,$output);
$fileInfo = $imageProc->getImageDimensions($output);
$result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands, array("Note on 'niceText':","'niceText' is a concept that tries to improve the antialiasing of the rendered type by actually rendering the textstring in double size on a black/white mask, downscaling the mask and masking the text onto the image through this mask. This involves ImageMagick 'combine'/'composite' and 'convert'."));
$this->message($headCode,"Render text with TrueType font using 'niceText' option",
......
$imageProc->makeText($im,$conf,$workArea);
$output = $imageProc->tempPath.$imageProc->filenamePrefix.t3lib_div::shortMD5("GDwithText-niceText-shadow").".".$imageProc->gifExtension;
$imageProc->ImageGif ($im,$output);
$imageProc->ImageWrite($im,$output);
$fileInfo = $imageProc->getImageDimensions($output);
$result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands, array("Note on drop shadows:","Drop shadows are done my using ImageMagick to blur a mask through which the drop shadow is generated. The blurring of the mask only works in ImageMagick 4.2.9 and <i>not</i> ImageMagick 5 - which is why you may see a hard and not soft shadow."));
$this->message($headCode,"Render 'niceText' with a shadow under",
(10-10/10)