This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Setup & design » Transparency and texttoimage .. How ?!
expandshrink

Transparency and texttoimage .. How ?!

Transparency and texttoimage .. How ?!

Tuesday 13 December 2005 4:05:24 pm - 5 replies

Hi ...

Any way to get texttoimage with transparent bg ?!

Thanks in advance.

Tuesday 13 December 2005 4:41:42 pm

It's a quite interesting challange.
You should create a new template function similar to texttoimage, using a different image type (gif or png) because default seem to be png, you probably should add a function to make the background transparent in the libraries (see /lib/eztemplate/classes/eztemplateimageoperator.php) and make sure that the php gd extension support writing gif or png images.

Hope this help a little.

Tuesday 13 December 2005 5:46:57 pm

I had the same problem and fixed it by doing following modifications.

1. lib/ezimage/classes/ezimageinterface.php
Add a function called allocateTransparentColor to the eZImageInterface class:

function allocateTransparentColor ($color) {
	imagecolortransparent( $this->ImageObject, $color );
}

2. lib/eztemplate/classes/eztemplateimageoperator.php

function modify( ...) {
...

if ( $ini->hasVariable( $class, 'AbsoluteWidth' ) )
	$absoluteWidth =& $ini->variable( $class, 'AbsoluteWidth' );
if ( $ini->hasVariable( $class, 'AbsoluteHeight' ) )
	$absoluteHeight =& $ini->variable( $class, 'AbsoluteHeight' );

/* START ADDITION */
$transparentBackground = false;
if ( $ini->hasVariable( $class, 'TransparentBackground' ) )
	$transparentBackground = $ini->variable( $class, 'TransparentBackground' ) == "enabled";
/* END ADDITION */

...

$alternativeText = htmlspecialchars( $inputValue );
if ( is_string( $usecache ) )
	$md5Text = $usecache;
else
	/* START MODIFICATION */
	//$md5Text = md5( $inputValue . $family . $size . $angle . $xadj . $yadj . $wadj . $hadj . $absoluteWidth . $absoluteHeight . implode( ",", $bgcol ) . implode( ",", $textcol ) );
	$md5Text = md5( $transparentBackground. $inputValue . $family . $size . $angle . $xadj . $yadj . $wadj . $hadj . $absoluteWidth . $absoluteHeight . implode( ",", $bgcol ) . implode( ",", $textcol ) );
	/* END MODIFICATION */

...

if ( is_string( $usecache ) or !$usecache or
	!$this->hasImage( $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs ) )
{
	$layer =& eZImageTextLayer::createForText( $inputValue, $font,
                                     $wadj, $hadj, $angle,
                                     $absoluteWidth, $absoluteHeight );
	if ( !$layer )
	{
		$tpl->error( $operatorName, "Could not open font \"$family\", no image created", $placement );
		return;
	}
	$layer->allocateColor( 'bgcol', $bgcol[0], $bgcol[1], $bgcol[2] );
	$layer->allocateColor( 'textcol', $textcol[0], $textcol[1], $textcol[2] );
	
	/* START ADDITION */
	if ( $transparentBackground )
		$layer->allocateTransparentColor($layer->color( 'bgcol' ));
	/* END ADDITION */

	$layer->setTextColor( 'textcol' );

	if ( $storeImage )
		$this->storeImage( $layer, $this->CacheDir, 'imagetext', $md5Text, $alternativeText, $this->StoreAs );
	$layer->destroy();
	}
else

...

} // end function modify
            

Usage in texttoimage.ini:

[arial]
Family=arial
PointSize=30
XAdjustment=0
YAdjustment=0
WidthAdjustment=8
HeightAdjustment=6
BackgroundColor=#ffffff
TransparentBackground=enabled
TextColor=#000000

Greets, Gabriel

Modified on Tuesday 13 December 2005 5:51:29 pm by Gabriel R.

Tuesday 13 December 2005 6:07:39 pm

hmm ... thanks guyz .. but I don`t think I will paly with php code... for svn updates !

Wednesday 03 January 2007 2:29:26 pm

great works!

why this updates don't add to 3.9.0?

Friday 09 February 2007 12:19:36 pm

great works!

but how can I use this in extension for not override the original lib function?

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from