📄 class.tslib_gifbuilder.php
字号:
*/ function make() { // Get trivial data $XY = $this->XY; // Gif-start $this->im = $this->imagecreate($XY[0],$XY[1]); $this->w = $XY[0]; $this->h = $XY[1]; // backColor is set $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)) { $sKeyArray=t3lib_TStemplate::sortedKeyList($this->setup); foreach($sKeyArray as $theKey) { $theValue=$this->setup[$theKey]; if (intval($theKey) && $conf=$this->setup[$theKey.'.']) { switch($theValue) { // Images case 'IMAGE': if ($conf['mask']) { $this->maskImageOntoImage($this->im,$conf,$this->workArea); } else { $this->copyImageOntoImage($this->im,$conf,$this->workArea); } break; // Text case 'TEXT': if (!$conf['hide']) { if (is_array($conf['shadow.'])) { $this->makeShadow($this->im,$conf['shadow.'],$this->workArea,$conf); } if (is_array($conf['emboss.'])) { $this->makeEmboss($this->im,$conf['emboss.'],$this->workArea,$conf); } if (is_array($conf['outline.'])) { $this->makeOutline($this->im,$conf['outline.'],$this->workArea,$conf); } $conf['imgMap']=1; $this->makeText($this->im,$conf,$this->workArea); } break; // Text effects: case 'OUTLINE': if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) { $this->makeOutline($this->im,$conf,$this->workArea,$txtConf); } break; case 'EMBOSS': if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) { $this->makeEmboss($this->im,$conf,$this->workArea,$txtConf); } break; case 'SHADOW': if ($this->setup[$conf['textObjNum']]=='TEXT' && $txtConf=$this->checkTextObj($this->setup[$conf['textObjNum'].'.'])) { $this->makeShadow($this->im,$conf,$this->workArea,$txtConf); } break; // Other case 'BOX': $this->makeBox($this->im,$conf,$this->workArea); break; case 'EFFECT': $this->makeEffect($this->im,$conf); break; case 'ADJUST': $this->adjust($this->im,$conf); break; case 'CROP': $this->crop($this->im,$conf); break; case 'SCALE': $this->scale($this->im,$conf); break; case 'WORKAREA': if ($conf['set']) { $this->setWorkArea($conf['set']); // this sets the workArea } if (isset($conf['clear'])) { $this->workArea = $this->defaultWorkArea; // this sets the current to the default; } break; } } } } if ($this->setup['transparentBackground']) { // Auto transparent background is set $Bcolor = ImageColorExact($this->im, $BGcols[0],$BGcols[1],$BGcols[2]); 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'], intval($this->setup['transparentColor.']['closest'])); if ($Tcolor>=0) { imagecolortransparent($this->im, $Tcolor); } } } /********************************************* * * Various helper functions * ********************************************/ /** * Initializing/Cleaning of TypoScript properties for TEXT GIFBUILDER objects * * 'cleans' TEXT-object; Checks fontfile and other vital setup * Finds the title if its a 'variable' (instantiates a cObj and loads it with the ->data record) * Performs caseshift if any. * * @param array GIFBUILDER object TypoScript properties * @return array Modified $conf array IF the "text" property is not blank * @access private */ function checkTextObj($conf) { $conf['fontFile']=$this->checkFile($conf['fontFile']); if (!$conf['fontFile']){$conf['fontFile']='t3lib/fonts/nimbus.ttf';} if (!$conf['iterations']){$conf['iterations'] = 1;} if (!$conf['fontSize']){$conf['fontSize']=12;} if ($conf['spacing'] || $conf['wordSpacing']) { // If any kind of spacing applys, we cannot use angles!! $conf['angle']=0; } if (!isset($conf['antiAlias'])){$conf['antiAlias']=1;} $cObj =t3lib_div::makeInstance('tslib_cObj'); $cObj->start($this->data); $conf['fontColor'] = trim($cObj->stdWrap($conf['fontColor'], $conf['fontColor.'])); $conf['text']=$cObj->stdWrap($conf['text'],$conf['text.']); // Strip HTML if (!$conf['doNotStripHTML']) { $conf['text'] = strip_tags($conf['text']); } $this->combinedTextStrings[] = strip_tags($conf['text']); // Max length = 100 $tlen = intval($conf['textMaxLength']) ? intval($conf['textMaxLength']) : 100; $conf['text'] = substr($conf['text'],0,$tlen); if ((string)$conf['text']!='') { // Char range map thingie: $fontBaseName = basename($conf['fontFile']); if (is_array($this->charRangeMap[$fontBaseName])) { // Initialize splitRendering array: if (!is_array($conf['splitRendering.'])) { $conf['splitRendering.'] = array(); } $cfgK = $this->charRangeMap[$fontBaseName]['cfgKey']; if (!isset($conf['splitRendering.'][$cfgK])) { // Do not impose settings if a splitRendering object already exists: // Set configuration: $conf['splitRendering.'][$cfgK] = 'charRange'; $conf['splitRendering.'][$cfgK.'.'] = $this->charRangeMap[$fontBaseName]['charMapConfig']; // multiplicator of fontsize: if ($this->charRangeMap[$fontBaseName]['multiplicator']) { $conf['splitRendering.'][$cfgK.'.']['fontSize'] = round($conf['fontSize'] * $this->charRangeMap[$fontBaseName]['multiplicator']); } // multiplicator of pixelSpace: if ($this->charRangeMap[$fontBaseName]['pixelSpace']) { $travKeys = array('xSpaceBefore','xSpaceAfter','ySpaceBefore','ySpaceAfter'); foreach($travKeys as $pxKey) { if (isset($conf['splitRendering.'][$cfgK.'.'][$pxKey])) { $conf['splitRendering.'][$cfgK.'.'][$pxKey] = round($conf['splitRendering.'][$cfgK.'.'][$pxKey] * ($conf['fontSize'] / $this->charRangeMap[$fontBaseName]['pixelSpace'])); } } } } } if (is_array($conf['splitRendering.'])) { foreach($conf['splitRendering.'] as $key => $value) { if (is_array($conf['splitRendering.'][$key])) { if (isset($conf['splitRendering.'][$key]['fontFile'])) { $conf['splitRendering.'][$key]['fontFile'] = $this->checkFile($conf['splitRendering.'][$key]['fontFile']); } } } } return $conf; } } /** * Calculation of offset using "splitCalc" and insertion of dimensions from other GIFBUILDER objects. * * Example: * Input: 2+2, 2*3, 123, [10.w] * Output: 4,6,123,45 (provided that the width of object in position 10 was 45 pixels wide) * * @param string The string to resolve/calculate the result of. The string is divided by a comma first and each resulting part is calculated into an integer. * @return string The resolved string with each part (separated by comma) returned separated by comma * @access private */ function calcOffset($string) { $numbers=explode(',',$string); while(list($key,$val)=each($numbers)) { $val = trim($val); if ((string)$val==(string)intval($val)) { $value[$key]=intval($val); } else { $parts= t3lib_div::splitCalc($val,'+-*/%'); $value[$key]=0; reset($parts); while(list(,$part)=each($parts)) { $theVal = $part[1]; $sign = $part[0]; if ((string)intval($theVal)==(string)$theVal) { $theVal = intval($theVal); } elseif ('['.substr($theVal,1,-1).']'==$theVal) { $objParts=explode('.',substr($theVal,1,-1)); $theVal=0; if (isset($this->objBB[$objParts[0]])) { if ($objParts[1]=='w') {$theVal=intval($this->objBB[$objParts[0]][0]);} if ($objParts[1]=='h') {$theVal=intval($this->objBB[$objParts[0]][1]);} } } else { $theVal =0; } if ($sign=='-') {$value[$key]-=$theVal;} if ($sign=='+') {$value[$key]+=$theVal;} if ($sign=='/') {if (intval($theVal)) $value[$key]/=intval($theVal);} if ($sign=='*') {$value[$key]*=$theVal;} if ($sign=='%') {if (intval($theVal)) $value[$key]%=intval($theVal);} } $value[$key]=intval($value[$key]); } } $string = implode(',',$value); return $string; } /** * Returns an "imgResource" creating an instance of the tslib_cObj class and calling tslib_cObj::getImgResource * * @param string Filename value OR the string "GIFBUILDER", see documentation in TSref for the "datatype" called "imgResource" * @param array TypoScript properties passed to the function. Either GIFBUILDER properties or imgResource properties, depending on the value of $file (whether that is "GIFBUILDER" or a file reference) * @return array Returns an array with file information if an image was returned. Otherwise false. * @access private * @see tslib_cObj::getImgResource() * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=315&cHash=63b593a934 * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=282&cHash=831a95115d */ function getResource($file,$fileArray) { if (!t3lib_div::inList($this->imageFileExt, $fileArray['ext'])) { $fileArray['ext'] = $this->gifExtension; } $cObj =t3lib_div::makeInstance('tslib_cObj'); $cObj->start($this->data); return $cObj->getImgResource($file,$fileArray); } /** * Returns the reference to a "resource" in TypoScript. * * @param string The resource value. * @return string Returns the relative filepath * @access private * @see t3lib_TStemplate::getFileName() */ function checkFile($file) { return $GLOBALS['TSFE']->tmpl->getFileName($file); } /** * Calculates the GIFBUILDER output filename/path based on a serialized, hashed value of this->setup * * @param string Filename prefix, eg. "GB_" * @return string The relative filepath (relative to PATH_site) * @access private */ function fileName($pre) { // WARNING: In PHP5 I discovered that rendering with freetype of Japanese letters was totally corrupt. Not only the wrong glyphs are printed but also some memory stack overflow resulted in strange additional chars - and finally the reason for this investigation: The Bounding box data was changing all the time resulting in new images being generated all the time. With PHP4 it works fine. return $this->tempPath. $pre. ($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix'] ? $GLOBALS['TSFE']->fileNameASCIIPrefix(implode('_',array_merge($this->combinedTextStrings,$this->combinedFileNames)),intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix']),'_') : ''). t3lib_div::shortMD5(serialize($this->setup)). '.'.$this->extension(); } /** * Returns the file extension used in the filename * * @return string Extension; "jpg" or "gif"/"png" * @access private */ function extension() { switch(strtolower($this->setup['format'])) { case 'jpg': case 'jpeg': return 'jpg'; break; case 'png': return 'png'; break; case 'gif': return 'gif'; break; default: return $this->gifExtension; break; } }}if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_gifbuilder.php']) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['tslib/class.tslib_gifbuilder.php']);}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -