rtgx

Vytvorenie obrázku s vodoznakom (watermark)

Typoscipt setup

plugin.tx_extname_pi2 {
imageMask = fileadmin/img/watermarkMask.gif
imageBack = fileadmin/img/watermark.gif
}

Potrebné obrázky (príklad)

Watermark
Watermark
Watermark Mask
Watermark Mask

PHP

class tx_extname_pi2 extends tslib_pibase {

var $path = 'uploads/tx_extname/'; // Path to uploaded files

...

/**
* Compose two images - original image with mask in right bottom corner
*
* @param string $image: image name
* @return string $content: path+image (combined)
*/
function composeImage( $image ) {

if( !copy( $this->path.$image, $this->path.'w'.$image ) ) {
$this->content .= "failed to copy $image...\n";
}
else {
$file = $this->path.$image;
$outfile = $this->path.'w'.$image;

$this->imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
$this->imgObj->init();
$this->imgObj->mayScaleUp = 0;
$this->imgObj->tempPath = PATH_site.$this->imgObj->tempPath;

$imgInfo = $this->imgObj->getImageDimensions( $outfile );
$this->imgSize = array( $imgInfo[0], $imgInfo[1] );

$this->combineExec( $file, $this->conf['imageBack'], $this->conf['imageMask'], $outfile );
return $outfile;
}
}

function combineExec( $input, $overlay, $mask, $output ) {

$params = ' -colorspace GRAY +matte '; // -negate
$theMask = 'fileadmin/perfora/img/mask.gif';
$this->imgObj->imageMagickExec( $mask, $theMask, $params );

$cmd = t3lib_div::imageMagickCommand( 'combine', '-compose over +matte -gravity SouthEast -quality 90 '.$this->imgObj->wrapFileName( $input ).' '.$this->imgObj->wrapFileName( $overlay ).' '.$this->imgObj->wrapFileName( $theMask ).' '.$this->imgObj->wrapFileName( $output ) );
$this->IM_commands[] = array( $output, $cmd );
$ret = exec( $cmd );
t3lib_div::fixPermissions( $this->imgObj->wrapFileName( $output ) );

if( is_file( $theMask ) ) {
@unlink( $theMask );
}
return $ret;
}
}
Vytvorenie obrázku pomocou definovaných funkcií

Premenná $row['image'] obsahuje názov obrázku.

class tx_extname_pi2 extends tslib_pibase {
...
$image = '<img src="'.$this->composeImage( $row['image'] ).'" title="" alt="" />';
...
}