hey, for the first time I tried to night to make an image uploading script (no problems at all) and a page that fetches the images from the ftp server.
However, I store the images only in original size, but in the image gallery I want thumbnails to be linked to the original files. Thus, I thought I could use imagecopyresampled to create temporary thumbnails.
The current situation is that I get the a href-link to the original image, but no thumbnails are displayed. Any ideas?
//Content type
header('Content-type: image/jpeg');
//This works well, I fetch the path/directory of all available images
$std_path = 'playergallery/';
$subfolder = $pID;
$directory = $std_path.$subfolder;
if ($handle = opendir($directory)) {
$k = 0;
$file_array = array();
while (false !== ($file = readdir($handle))) {
if (false !== strpos($file,'.jpg', '.gif')) {
$file_array[$k] = $file;
$k += 1;
}
}
closedir($handle);
} else {
}
$n = count($file_array);
//For all available images, the following is executed
for ($image_no=0; $image_no<$n; $image_no++)
{
//The url/path to the image used for my href-link at the bottom
$img_src = $directory . "/" . $file_array[$image_no];
//File/name
$filename = $img_src;
//The width and height of my temporary thumbnail that is supposed to be created for all images in the loop
$width = 180;
$height = 100;
//The new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
}
else {
$height = $width/$ratio_orig;
}
//Resampling
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output (a href to the original file and a linked thumnail)
echo "<a href=\"$img_src\" onclick=\"return hs.expand(this)\">";
imagejpeg($image_p, null, 100);
echo "</a>";
}
The linked thumbnail does not show up.
Instead for an image, I get lots of binary(?) code like: ÿØÿàJFIFÿþ<| Õ¾%|zñg‰ü9¨øfÓá§Ä\xâçX‚ÞM;FÔD·ðj¾hÞÒ)<¹ žê8..e¶µûÅŸðMƒ>øWáÔðWÆkÿ'Ó?µoìíõ(i—ò,Ëq§øm¢²Ö ÒžH£mBk‰‚•å¨Ü?%õŸ†ºÖ—«k¶#ñ•»jú\º¦Žú5Ëê7¦Ëc¶