Forums / Setup & design / Transparency and texttoimage .. How ?!

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

Transparency and texttoimage .. How ?!

Author Message

Selmah Maxim

Tuesday 13 December 2005 7:05:24 am

Hi ...

Any way to get texttoimage with transparent bg ?!

Thanks in advance.

Daniele P.

Tuesday 13 December 2005 7:41:42 am

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.

Gabriel R.

Tuesday 13 December 2005 8:46:57 am

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

Selmah Maxim

Tuesday 13 December 2005 9:07:39 am

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

Ulitsa Tal Arik

Wednesday 03 January 2007 5:29:26 am

great works!

why this updates don't add to 3.9.0?

Daniele Nocentini

Friday 09 February 2007 3:19:36 am

great works!

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

Antica Bottega Digitale srl
http://www.abd.it