Hi,
I've made a thumbnail script and it's all working and stuff, but if I want to use it in existing code (with include) it keeps displaying some data instead of the image like this:
ÿØÿàJFIFÿþ ü1L©éÿ‡¸zíéלã5ô;j«keqy#|–ö¦PY¶)pŒÑ«žÊXI8’}hÄî¿fŸÙŽ}R->Ãöjø{wÝÁ´ƒàÿÃø’M<»Ãr“ÌžbZÝɸ™PÁãy?fÙ×Äß
and more of that crap... I think I need to use headers in some sort of way, but I can't figure it out here's my code:
photoalbum.php
<?php
include "nav.php";
include "resize.php";
echo "<br><br>";
if (isset ($id)) {
$query = "SELECT nick,avater_filename FROM users WHERE id='$id'";
$exec = mysql_query ($query);
$result = mysql_fetch_array ($exec);
$nick = $result["nick"];
$nick_dir = str_replace (" ","_", $nick);
$avater_filename = $result["avater_filename"];
$query = "SELECT filename, comments, date FROM photos WHERE user='$id' ORDER BY filename";
$exec = mysql_query ($query);
while ($result = mysql_fetch_array ($exec)) {
$filename = $result["filename"];
$photo = "photos/$nick_dir/$filename";
create_thumbnail ($photo);
}
}
?>
resize.php
<?php
function create_thumbnail (&$photo) {
$photo = imagecreatefromjpeg ("./$photo");
$photo_dimensions_width = imagesx ($photo);
$photo_dimensions_height = imagesy ($photo);
if ($photo_dimensions_width == $photo_dimensions_height) {
$thumb_dimensions_width = 100;
$thumb_dimensions_height = 100;
}
elseif ($photo_dimensions_width > $photo_dimensions_height) {
$value = $photo_dimensions_width / 100;
$thumb_dimensions_width = 100;
$thumb_dimensions_height = round ($photo_dimensions_height / $value);
}
else {
$value = $photo_dimensions_height / 100;
$thumb_dimensions_height = 100;
$thumb_dimensions_width = round ($photo_dimensions_width / $value);
}
$thumb = imagecreatetruecolor ($thumb_dimensions_width, $thumb_dimensions_height);
imagecopyresampled ($thumb, $photo, 0, 0, 0, 0, $thumb_dimensions_width, $thumb_dimensions_height, $photo_dimensions_width, $photo_dimensions_height);
ImageJpeg($thumb,'',100);
}
?>