Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Andy - GalleryManagerGD image width and height tags

Quote Reply
Andy - GalleryManagerGD image width and height tags
Andy, GalleryManagerGD. Is it possible to have some sort of function that will pull the dimensions of the image and add width="" and height="" to the <img src=...> tag?
Quote Reply
Re: [MJB] Andy - GalleryManagerGD image width and height tags In reply to
Hi,

This is something I use on my-free-css-templates.com to do it:

Add the following to /admin/Plugins/Thumb_Images_GD.pm:

Code:
sub ThumbSize {
# -------------------------------------------------------------------
# This subroutine will get called whenever a tag is called in the templates.
# It will grab the URL to the file...small file that is...and return it
# Call with <%Plugins::Thumb_Images::ThumbURL($ID,FieldName)%>

my ($ID,$field,$table) = @_;

use Image::Size 'html_imgsize';

$table ||= 'Links';

# make sure a fieldname and ID are provided...
if (!$ID || !$field) { return "You need to define the ID and fieldname. Example: &lt\;%Plugins::Thumb_Images::ThumbURL(\$ID,FieldName)%&gt\;"; }

# get the actual path to where the file is/will be saved...
my $schema = $DB->table('Links')->cols;
my $path = $schema->{$field}->{'file_save_in'};
$path =~ s,/$,,; # get rid of trailing / at end of $path


# now lets grab the path to this image...from $hit->{ID}
my $col = $field; # column name where file is held
my $tbl = $DB->table( 'Links' );
my $fh = $tbl->file_info( $col, $ID ); # return a glob reference to the file that you can print <$fh> if you want

my $rel_path;
if ($fh) {
$rel_path = $fh->File_RelativePath;
}
undef $fh; # explicit close of the filehandle for good measure

# create the variable for where the small image will be held...
my @img_create = split("/",$rel_path);
my $count = $#img_create;

# create the path, and small image name...
my $rel_path_small = undef; # make sure we have this variable as an undef, otherwise we get probs...
for (my $i = 0; $i < $count; $i++) { $rel_path_small .= $img_create[$i] . "/"; }
$rel_path_small .= "small-" . $img_create[$count]; # create the small image name...

my $the_path = $path . $rel_path_small;

return html_imgsize($the_path);



}

..then in your template (link.html), run:

Code:
<%set image_size_small = Plugins::Thumb_Images::ThumbSize ($ID,'Image')%>

Then just add this in the <img bit, where you want to set the dimensions:

Code:
<%image_size_small%>

This outputs stuff like:

<img src="http://my-free-css-templates.com.nmsrv.com/static/uploads/9/small-1089-Screenshots2.jpg" alt="Blue 3 Column Free Template" border="0" height="82" width="100">

Hope that helps :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Andy - GalleryManagerGD image width and height tags In reply to
Thanks Andy, I'll give that a try.