By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,811 Members | 785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,811 IT Pros & Developers. It's quick & easy.

problem displaying images as thumbnails

P: n/a
Hello
Im having problems displaying my images as thumbnails in a table. My code
for producing the new width and height from the original image is as follows
**************************************************
if ($ImagePath) {
//$Image = WEB_ROOT . 'images/PupilTester/' . $ImagePath;
$Image = 'images/PupilTester/' . $ImagePath;
} else {
$Image ='images/PupilTester/nopicture.bmp';
}

$size = getimagesize($image);
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$height = 150;
$percent = ($size[1] / $height);
$width = ($size[0] / $percent);
}
else if ($width > 150)
{
$width = 150;
$percent = ($size[0] / $width);
$height = ($size[1] / $percent);
}
//echo "<img src\"image/path/image.jpg\" height=\"$height\"
width=\"$width\" />";
************************************************** ************

and in my table to display the thumbnail I have

************************************************** ************
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo $Image;
?> width= <?php echo "$width"?> height= <?php echo "$height"?>>
</div></td>
</tr>
************************************************** **************
However the images are not showing at all. The cells of the table are blank.
But if I use

*********************************************
<td><img src=<?php echo $Image; ?>></td>
</tr>
*******************************************
The images show full size as normal. Can anyone see where Ive gone wrong
Thaks
Ian
Oct 18 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Ian Davies wrote:
Hello
Im having problems displaying my images as thumbnails in a table. My code
for producing the new width and height from the original image is as follows
**************************************************
if ($ImagePath) {
//$Image = WEB_ROOT . 'images/PupilTester/' . $ImagePath;
$Image = 'images/PupilTester/' . $ImagePath;
} else {
$Image ='images/PupilTester/nopicture.bmp';
}

$size = getimagesize($image);
$height = $size[1];
$width = $size[0];
if ($height > 150)
{
$height = 150;
$percent = ($size[1] / $height);
$width = ($size[0] / $percent);
}
else if ($width > 150)
{
$width = 150;
$percent = ($size[0] / $width);
$height = ($size[1] / $percent);
}
//echo "<img src\"image/path/image.jpg\" height=\"$height\"
width=\"$width\" />";
************************************************** ************

and in my table to display the thumbnail I have

************************************************** ************
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo $Image;
?> width= <?php echo "$width"?> height= <?php echo "$height"?>>
</div></td>
</tr>
************************************************** **************
However the images are not showing at all. The cells of the table are blank.
But if I use

*********************************************
<td><img src=<?php echo $Image; ?>></td>
</tr>
*******************************************
The images show full size as normal. Can anyone see where Ive gone wrong

Wrong approach.

Use a separate script for showing the images

<img src="showthumbnail.php?img=xxxxxx">

Regards
Stefan

Thaks
Ian

Oct 18 '05 #2

P: n/a
Ian Davies said the following on 18/10/2005 20:14:
Hello
Im having problems displaying my images as thumbnails in a table. My code
for producing the new width and height from the original image is as follows <...SNIP CODE...>
and in my table to display the thumbnail I have

************************************************** ************
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo $Image;
?> width= <?php echo "$width"?> height= <?php echo "$height"?>>
</div></td>
</tr>
************************************************** **************
However the images are not showing at all. The cells of the table are blank.
But if I use

*********************************************
<td><img src=<?php echo $Image; ?>></td>
</tr>
*******************************************
The images show full size as normal. Can anyone see where Ive gone wrong


Wouldn't the simplest thing to do be to look at the HTML source in the
browser, and ensure that the correct HTML is being output by PHP? If it
isn't, then correct PHP code accordingly...
--
Oli
Oct 18 '05 #3

P: n/a
Stefan Rybacki said the following on 18/10/2005 20:23:
Ian Davies wrote:
Hello
Im having problems displaying my images as thumbnails in a table. My code
for producing the new width and height from the original image is as
follows <...SNIP CODE...> The images show full size as normal. Can anyone see where Ive gone wrong


Wrong approach.

Use a separate script for showing the images

<img src="showthumbnail.php?img=xxxxxx">


Not in this case. The OP is outputting the image URL, not the image data
itself...
--
Oli
Oct 18 '05 #4

P: n/a
Hello
Here is part of the source viewed from the browser. It looks like the
correct images are being found but it looks like the width and height
variables are not working. I am new to php and despite trying a few
alterations to the syntax am not having much luck.

Also I am outputing the images themselves not the urls

Ian
************************************************** *********
</div></td>
<td rowspan="5" valign="top">11&nbsp;</td>
<td rowspan="5" valign="top">Metal plates were inserted into 3 shoot
tips (below). Which shoot would grow to the right?</td>
<td rowspan="5" valign="top"><div align="center"></div>
Type answer (Diagram)</td>
<td valign="top"><div align="left"></div> </td>
<td rowspan="5" valign="top"><div align="left"><img
src=images/PupilTester/PlantHormones.jpg width= height= >
</div></td>
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:CW***************@newsfe5-win.ntli.net... Ian Davies said the following on 18/10/2005 20:14:
Hello
Im having problems displaying my images as thumbnails in a table. My code for producing the new width and height from the original image is as follows
<...SNIP CODE...>

and in my table to display the thumbnail I have

************************************************** ************
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo

$Image; ?> width= <?php echo "$width"?> height= <?php echo "$height"?>>
</div></td>
</tr>
************************************************** **************
However the images are not showing at all. The cells of the table are blank. But if I use

*********************************************
<td><img src=<?php echo $Image; ?>></td>
</tr>
*******************************************
The images show full size as normal. Can anyone see where Ive gone wrong


Wouldn't the simplest thing to do be to look at the HTML source in the
browser, and ensure that the correct HTML is being output by PHP? If it
isn't, then correct PHP code accordingly...
--
Oli

Oct 18 '05 #5

P: n/a
Ian Davies wrote:
$Image ='images/PupilTester/nopicture.bmp';
Bad idea to use a BMP on the web. Try PNG (or GIF).
$size = getimagesize($image);
Variable names are case sensitive! Use $image or $Image consistently.
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo $Image;
?> width= <?php echo "$width"?> height= <?php echo "$height"?>>


Use quotation marks to enclose tag parameter values in HTML, but not when
echoing PHP variables:

<img src="<?php echo $Image; ?>"
width="<?php echo $width; ?>"
height="<?php echo $height; ?>">

--
E. Dronkert
Oct 18 '05 #6

P: n/a
Found it. Two problems

****************************************
$size = getimagesize($image);
***************************************
should be
*****************************************
$size = getimagesize($Image);
****************************************
case sensitive (silly me)

also in the table to display thumbnails
****************************************
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo $Image;
?> width= <?php echo "$width"?> height= <?php echo "$height"?>>
************************************************** ***************
should be
******************************************
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo $Image;
?> width= "<?php echo $width?>" height= "<?php echo $height?>">
******************************************

Thanks for your help
Ian
"Ian Davies" <ia********@virgin.net> wrote in message
news:4c************@newsfe6-win.ntli.net...
Hello
Here is part of the source viewed from the browser. It looks like the
correct images are being found but it looks like the width and height
variables are not working. I am new to php and despite trying a few
alterations to the syntax am not having much luck.

Also I am outputing the images themselves not the urls

Ian
************************************************** *********
</div></td>
<td rowspan="5" valign="top">11&nbsp;</td>
<td rowspan="5" valign="top">Metal plates were inserted into 3

shoot tips (below). Which shoot would grow to the right?</td>
<td rowspan="5" valign="top"><div align="center"></div>
Type answer (Diagram)</td>
<td valign="top"><div align="left"></div> </td>
<td rowspan="5" valign="top"><div align="left"><img
src=images/PupilTester/PlantHormones.jpg width= height= >
</div></td>
"Oli Filth" <ca***@olifilth.co.uk> wrote in message
news:CW***************@newsfe5-win.ntli.net...
Ian Davies said the following on 18/10/2005 20:14:
Hello
Im having problems displaying my images as thumbnails in a table. My code for producing the new width and height from the original image is as follows
<...SNIP CODE...>

and in my table to display the thumbnail I have

************************************************** ************
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo

$Image; ?> width= <?php echo "$width"?> height= <?php echo "$height"?>>
</div></td>
</tr>
************************************************** **************
However the images are not showing at all. The cells of the table are blank. But if I use

*********************************************
<td><img src=<?php echo $Image; ?>></td>
</tr>
*******************************************
The images show full size as normal. Can anyone see where Ive gone wrong


Wouldn't the simplest thing to do be to look at the HTML source in the
browser, and ensure that the correct HTML is being output by PHP? If it
isn't, then correct PHP code accordingly...
--
Oli


Oct 18 '05 #7

P: n/a
Oli Filth wrote:
Stefan Rybacki said the following on 18/10/2005 20:23:
Ian Davies wrote:
Hello
Im having problems displaying my images as thumbnails in a table. My
code
for producing the new width and height from the original image is as
follows
<...SNIP CODE...>
The images show full size as normal. Can anyone see where Ive gone wrong


Wrong approach.

Use a separate script for showing the images

<img src="showthumbnail.php?img=xxxxxx">


Not in this case. The OP is outputting the image URL, not the image data
itself...


Damn, you're right. I should better read. ;) Well the subject made me think he is creating
real thumbnails not just faked ones.

Regards
Stefan

Oct 18 '05 #8

P: n/a
Thanks
Trial and error brought me to the same conclusion
I will remember this
Ian

"Ewoud Dronkert" <fi*******@lastname.net.invalid> wrote in message
news:dn********************************@4ax.com...
Ian Davies wrote:
$Image ='images/PupilTester/nopicture.bmp';


Bad idea to use a BMP on the web. Try PNG (or GIF).
$size = getimagesize($image);


Variable names are case sensitive! Use $image or $Image consistently.
<td rowspan="5" valign="top"><div align="left"><img src=<?php echo $Image; ?> width= <?php echo "$width"?> height= <?php echo "$height"?>>


Use quotation marks to enclose tag parameter values in HTML, but not when
echoing PHP variables:

<img src="<?php echo $Image; ?>"
width="<?php echo $width; ?>"
height="<?php echo $height; ?>">

--
E. Dronkert

Oct 18 '05 #9

P: n/a
Ian Davies wrote:
Hello
Here is part of the source viewed from the browser. It looks like the
correct images are being found but it looks like the width and height
variables are not working. I am new to php and despite trying a few
alterations to the syntax am not having much luck.

Also I am outputing the images themselves not the urls
no you don't. $Image contains the url to the image not the image data itself.
Ewoud gave you a good hint, which you should follow.

Regards
Stefan
...

Oct 18 '05 #10

P: n/a
Ewoud Dronkert wrote:
Ian Davies wrote:
$Image ='images/PupilTester/nopicture.bmp';

Bad idea to use a BMP on the web. Try PNG (or GIF).

$size = getimagesize($image);

Variable names are case sensitive! Use $image or $Image consistently.

<td rowspan="5" valign="top"><div align="left"><img src=<?php echo $Image;
?> width= <?php echo "$width"?> height= <?php echo "$height"?>>

Use quotation marks to enclose tag parameter values in HTML, but not when
echoing PHP variables:

<img src="<?php echo $Image; ?>"
width="<?php echo $width; ?>"
height="<?php echo $height; ?>">


Actually, quotes are not required for numeric data like height and
width. But it doesn't hurt and is a good habit to get into.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 19 '05 #11

P: n/a
Jerry Stuckle wrote:
Use quotation marks to enclose tag parameter values in HTML


Actually, quotes are not required for numeric data


Yeah but they are for XHTML conformance. I always like to make my pages at
least XHTML 1.0 Transitional conformant.

--
E. Dronkert
Oct 19 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.