PDA

View Full Version : Gd2


pete3005
07-30-2002, 01:36 PM
I would like to make a suggestion that you upgrade to GD2 so we can make use of some of the new image functions that are not available in the versions < GD2 :)

TIA

Pete

harmonic
07-30-2002, 03:19 PM
does gd2 have *.gif support?

i was writing a script earlier that uploaded an image and checked the dimensions... but it would only support jpegs...

pete3005
07-30-2002, 03:31 PM
Hi Harmonic,

Yes it does, but for checking image size you do not need GD installed anyway.

Use the PHP GetImageSize() function, that works with any GIF, JPG, PNG, SWF, PSD, TIFF or BMP image files.

Here is an example (just incase you don't know):

$filename = "images/holidayphoto.jpg";
$data = getimagesize($filename);

This returns an numerative array where:

$data[0] = width in pixels
$data[1] = height in pixels
$data[2] = filetype index (e.g. 1 = image/gif, 2 = image/jpeg, etc.)
$data[3] = HTML attributes (e.g. height="y" width="x")

To get an image size in a page I made this class

<?php

class MyImage
{

//set my variables for this class

var $imagename;
var $imagewidth;
var $imageheight;
var $imagealt;

//start contructor function that excutes when called

function MyImage($myimagename,$imalt)
{

echo "<img src=\"";
echo $this->imagename = $myimagename;
echo "\"";
$this->imagewidth = getimagesize("$myimagename");
echo " width=\"";
echo $this->imagewidth[0];
echo "\"";
$this->imageheight = getimagesize("$myimagename");
echo " height=\"";
echo $this->imageheight[1];
echo "\"";
echo " alt=\"";
echo $this->imagealt = $imalt;
echo "\" border=\"0\">";
}

//end class
}
?>

Then call is like this:

<?php
$showimage = @new
MyImage("prodimages/".$stdetail->Image,$stdetail->Name);
?>

The first argument is the image location and name, in the above case, it comes from MySQL, the second argument is the alt text which is coming from MySQL too.

That outputs:

<img src="prodimages/6768d.jpg" width="250" height="220" alt="Diamond channel set eternity ring" border="0">

HTH


Pete

harmonic
07-30-2002, 03:38 PM
thanks for the input.. i was using imagesx() and imagesy().. ill try out what you said

harmonic
07-30-2002, 04:52 PM
thanks :D worked like a charm


function checkwh($loc){
$props = getimagesize($loc);
if($props[0] > 50 || $props[1] > 50){
return FALSE;
} else {
return TRUE;
}
}