Re: Re: Re: [SMARTY] hello again :)

From: Date: Mon, 25 Nov 2002 22:54:24 +0000
Subject: Re: Re: Re: [SMARTY] hello again :)
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6551@lists.php.net to get a copy of this message
is that necessary? works fine here ... --- At 2002-11-25, 16:39:00, Monte Ohrt <monte@ispi.net> wrote: >It would be nice if DOCUMENT_ROOT was used to find the image, that way >you don't need full system paths in the template, just use the path >relative to document root like you would with a normal IMG tag. > >Monte > >On Mon, 2002-11-25 at 16:04, Rasmus Schultz wrote: >> >put an echo "DEBUG"; statement in the fuction.img.php file, see if is >> >even getting loaded. >> >> oh man. >> >> yeah, it was getting loaded, but check this out: >> >> if empty($width) { $width = $size[0]; }; >> if empty($height) { $height = $size[1]; }; >> >> see something missing? >> yes, the paranthesis after the if-statements. d'oh. >> well, good then - problem solved - thanks for your suggestions :) >> >> now, here's the tested and working plugin: >> >> <?php >> >> /* >> * Smarty plugin >> * ------------------------------------------------------------- >> * File: function.img.php >> * Type: function >> * Name: img >> * Version: 1.0 >> * Date: November 25th, 2002 >> * Purpose: inserts an imagetag, automatically examining and >> * using the width and height in the HTML tag. >> * NOTE: If you need to add other properties to your IMG tag >> * you should use "function.imgsize.php" instead. >> * Input: "src" must specify the filename of the image >> * "width" and "height" optionally specify the width >> * and/or height of the image - if unspecified, the >> * plugin examines the dimensions of the image. >> * "border" is optional and defaults to zero. >> * Author: Rasmus Schultz <m(at)mindplay.dk> >> * Example: {img src="my.gif" border=1} >> * ------------------------------------------------------------- >> */ >> >> function smarty_function_img($params, &$smarty) >> { >> extract($params); >> >> if (empty($src)) { >> $smarty->trigger_error("image: 'src' argument required"); >> return false; >> } >> >> if (empty($width) or empty($height)) { >> if (!($size = getimagesize($src))) { >> $smarty->trigger_error("image: unable to get image information"); >> return false; >> } >> if (empty($width)) { $width = $size[0]; }; >> if (empty($height)) { $height = $size[1]; }; >> } >> >> if (empty($border)) { $border = 0; }; >> >> echo "<IMG SRC=\"$src\" WIDTH=$width HEIGHT=$height >> BORDER=$border>"; >> } >> >> /* vim: set expandtab: */ >> >> ?> >> >> >> >> only one small problem then - in some situations, you'll want to >> use additional plugins, or add other properties to your IMG tag ... >> like for example if I wanted a popup text on my image. >> >> the only solution I could come up with, is to write a second >> plugin, which returns ONLY the width and height properties, so >> you'll have to write the rest yourself ... unfortunately, this >> means you have to type the image filename twice, so it's not >> very elegant :/ >> >> anyone got any suggestion for a more elegant solution?? >> >> meanwhile, here's the other plugin: >> >> >> >> <?php >> >> /* >> * Smarty plugin >> * ------------------------------------------------------------- >> * File: function.imgsize.php >> * Type: function >> * Name: imgsize >> * Version: 1.0 >> * Date: November 25th, 2002 >> * Purpose: inserts WIDTH and HEIGHT properties for an IMG tag >> * NOTE: Unless you want to add additional properties to >> * your IMG tag, using "function.img.php" is simpler. >> * Input: "file" must specify the filename of the image. >> * Author: Rasmus Schultz <m(at)mindplay.dk> >> * Example: <IMG SRC="my.gif" {imgsize file="my.gif"} {popup >> text="Click me"}> >> * ------------------------------------------------------------- >> */ >> >> function smarty_function_imgsize($params, &$smarty) >> { >> extract($params); >> >> if (empty($file)) { >> $smarty->trigger_error("image: 'src' argument required"); >> return false; >> } >> >> if (!($size = getimagesize($file))) { >> $smarty->trigger_error("image: unable to get image information"); >> return false; >> } >> >> echo $size[3]; >> } >> >> /* vim: set expandtab: */ >> >> ?> >> >> >-- >Monte Ohrt <monte@ispi.net>

« previous php.smarty.general (#6551) next »