Jump to content

[SOLVED] image not displaying


Recommended Posts

I posted this question earlier but still no luck. for some reason my echo on the last line of the code doesn't produce an image and i'm not sure why any ideas.

 

thanks

 

 
<?php 

$img_path = "file/".$rows ['file'];

$image_t = getimagesize($img_path); 

imageResize($image_t[0],  
$image_t[1], 100); 

function imageResize($width, $height, $target) {  

if ($width > $height) { 
$percentage = ($target / $width); 
} else { 
$percentage = ($target / $height); 
} 

$width = round($width * $percentage); 
$height = round($height * $percentage); 

return "width=\"$width\" height=\"$height\""; 
} 

echo "<img src=$image_t>";

?>

Link to comment
https://forums.phpfreaks.com/topic/104850-solved-image-not-displaying/
Share on other sites

The source to the image isn't $image_t, since that contains the array returned by getimagesize(). Also, you're not 'catching' the returned string of your function. Is this what you want?:

 

<?php
$img_path = "file/".$rows ['file'];

$image_t = getimagesize($img_path); 

//edited this
$wh = imageResize($image_t[0],  
$image_t[1], 100);

function imageResize($width, $height, $target) {

if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}

$width = round($width * $percentage);
$height = round($height * $percentage);

return "width=\"$width\" height=\"$height\"";
}

//and this
echo "<img src=\"$img_path\" $wh />";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.