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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 16:12:13
Script start
Timing: Jan 18 2025 16:12:13
Module start 'layout'
Timing: Jan 18 2025 16:12:13
Module start 'content'
Timing: Jan 18 2025 16:12:13
Module end 'content'
Timing: Jan 18 2025 16:12:13
Script end

Main resources:

Total runtime0.6693 sec
Peak memory usage4,096.0000 KB
Database Queries72

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 587.9375152.6250
Module start 'layout' 0.00730.0034 740.562539.4453
Module start 'content' 0.01070.6571 780.0078677.5391
Module end 'content' 0.66780.0015 1,457.546916.1563
Script end 0.6692  1,473.7031 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.5157160.0002
Check MTime0.00140.2114160.0001
Mysql Total
Database connection0.00160.237710.0016
Mysqli_queries0.607190.7089720.0084
Looping result0.00080.1179700.0000
Template Total0.638895.420.3194
Template load0.00220.332820.0011
Template processing0.636695.110320.3183
Template load and register function0.00030.049210.0003
states
state_id_array0.00110.167810.0011
state_identifier_array0.00110.164220.0005
Override
Cache load0.00190.2826300.0001
Sytem overhead
Fetch class attribute can translate value0.00060.090350.0001
Fetch class attribute name0.00150.225580.0002
XML
Image XML parsing0.00150.220550.0003
class_abstraction
Instantiating content class attribute0.00000.002380.0000
General
dbfile0.00110.1622220.0000
String conversion0.00000.001540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs