GD Thumbnails

He has: 4 posts

Joined: Mar 2002

Hi
Please can anyone help?

I know how to make images uploaded, into thumbnails via "GD"

but not how to make a thumbnail of a
image hosted elsewhere, can this be done using GD?

Many thanks for any help!

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

What is "GD"???

He has: 4 posts

Joined: Mar 2002

THANKS EVERYONE FOR ALL YOUR HELP!
Best Regards
lengoundry

Britton's picture

He has: 25 posts

Joined: Mar 2004

Yes, I've done it. I'd be glad to give you my thumbnail file and show you how to use it.

Britton's picture

He has: 25 posts

Joined: Mar 2004

PM me or instant message me at BrittonKeene

Busy's picture

He has: 6,151 posts

Joined: May 2001

The image would have to be loaded through GD to make a thumbnail, giving it a URL may work but thats basically hotlinking (sucking up someone elses bandwidth)

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Megan: http://www.boutell.com/gd/

boutell.com/gd/ wrote: What is the GD library? GD is an open source code library for the dynamic creation of images by programmers. GD is written in C, and "wrappers" are available for Perl, PHP and other languages. GD creates PNG, JPEG and GIF images, among other formats. GD is commonly used to generate charts, graphics, thumbnails, and most anything else, on the fly. While not restricted to use on the web, the most common applications of GD involve web site development.

So you give it an image, tell it to do stuff (like resize to 50 x 50) and it does it. Nice thing is that you can use it in a script, so uploaded files can be manipulated on the fly, which is what lengoundry's trying to do here.

Reading the blurb it's mainly used for drawing graphs and such, so my guess is it's used in a lot of stats packages.

a Padded Cell our articles site!

He has: 4 posts

Joined: Mar 2002

Hi to all
many thanks for all the reply's
here is how I get thumbnails via GD
All I would like to know is what code would I use
to make thumbnails of images hosted elsewhere
using GD.
THANKS AGAIN EVERYONE FOR YOUR HELP!
Best Regards
Len

############################
### make thumbnail using GD

my $base; my $dir; my $ext;
($base, $dir, $ext) = fileparse($form{'UPIMAGE1'});
my $srcimage;
my $maxheight = 75;
my $maxwidth = 75;
if ($base =~ /.+(\.jpg|\.jpeg)$/i) {
$srcimage = GD::Image->newFromJpeg("$config{'imagebase'}/$form{'UPIMAGE1'}");
}
if ($base =~ /.+\.gif$/i) {
$srcimage = GD::Image->newFromGif("$config{'imagebase'}/$form{'UPIMAGE1'}");
}
my ($srcW,$srcH) = $srcimage->getBounds();
my $wdiff = $srcW - $maxwidth;
my $hdiff = $srcH - $maxheight;
my $newH; my $newW; my$aspect;

##this maintains the aspect of the image
if ($wdiff > $hdiff) {
$newW = $maxwidth;
$aspect = ($newW/$srcW);
$newH = int($srcH * $aspect);
} else {
$newH = $maxheight;
$aspect = ($newH/$srcH);
$newW = int($srcW * $aspect);
}

my $newimage = new GD::Image($newW,$newH);
$newimage->copyResized($srcimage,0,0,0,0,$newW,$newH,$srcW,$srcH);
open(OUT, ">$config{'thumbbase'}/$base") || die "Cannot create thumbnail: $!\n";
binmode OUT;
print OUT $newimage->jpeg;
close OUT;

### End of Thumbnail creation
##############################

Busy's picture

He has: 6,151 posts

Joined: May 2001

JeevesBond, GD is like image::mavick, does a lot more than graphs, can make images on the fly, like the security ones seen on forums but can change formats, crop, resize, add text, blur, sharpen, resize, rotate .... Is like a mini ifranview online

lengoundry, this part of the code wouldn't need to be touched, you'd just have to make sure $base, $dir and $ext had the right values, ie: ext was the file extension that is actually an image ... I don't believe you can do it as the code need ths image to resize, using just a link would cause all sorts of issues, security related as well. Did you email/pm Britton ?

He has: 4 posts

Joined: Mar 2002

Busy wrote: JeevesBond, GD is like image::mavick, does a lot more than graphs, can make images on the fly, like the security ones seen on forums but can change formats, crop, resize, add text, blur, sharpen, resize, rotate .... Is like a mini ifranview online

lengoundry, this part of the code wouldn't need to be touched, you'd just have to make sure $base, $dir and $ext had the right values, ie: ext was the file extension that is actually an image ... I don't believe you can do it as the code need ths image to resize, using just a link would cause all sorts of issues, security related as well. Did you email/pm Britton ?

Hi
Many thanks for your reply!
I know image magick can do this
but my host server only has GD

Did you email/pm Britton ?

I will do that now.
thanks again for your help!

Best Regards
Len

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.