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

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

eZ debug

Timing: Jan 18 2025 11:12:45
Script start
Timing: Jan 18 2025 11:12:45
Module start 'content'
Timing: Jan 18 2025 11:12:46
Module end 'content'
Timing: Jan 18 2025 11:12:46
Script end

Main resources:

Total runtime1.1996 sec
Peak memory usage4,096.0000 KB
Database Queries209

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0095 588.8594180.8281
Module start 'content' 0.00951.0487 769.6875682.6172
Module end 'content' 1.05820.1413 1,452.3047337.0859
Script end 1.1995  1,789.3906 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00410.3443210.0002
Check MTime0.00160.1300210.0001
Mysql Total
Database connection0.00180.148510.0018
Mysqli_queries1.113592.82182090.0053
Looping result0.00240.20212070.0000
Template Total1.160496.720.5802
Template load0.00260.218920.0013
Template processing1.157896.515820.5789
Template load and register function0.00020.018810.0002
states
state_id_array0.00430.355810.0043
state_identifier_array0.00110.092320.0006
Override
Cache load0.00210.1770300.0001
Sytem overhead
Fetch class attribute can translate value0.00180.152860.0003
Fetch class attribute name0.00300.247280.0004
XML
Image XML parsing0.00200.165260.0003
class_abstraction
Instantiating content class attribute0.00000.001280.0000
General
dbfile0.00300.2466330.0001
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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