Hello. I got the following code trying to make a thumbnail. I works if i dont set height and getimagesize for width only but i want to set the height as well. I changed the following script and the thumb is correct in dimension but it goes black. What to do ?
Code: Select all
<?php
$final_width_of_image = 100;
$thumbheight = 100;
$path_to_image_directory = 'images/fullsized/';
$path_to_thumbs_directory = 'images/thumbs/';
if (isset($_FILES['myphoto'])) {
if (preg_match('/[.](jpg)|(JPG)|(JEPG)|(gif)|(png)$/', $_FILES['myphoto']['name'])) {
$filename = $_FILES['myphoto']['name'];
$source = $_FILES['myphoto']['tmp_name'];
$target = $path_to_image_directory . $filename;
move_uploaded_file($source, $target);
if (preg_match('/[.](jpg)$/', $filename)) {
$myimage = imagecreatefromjpeg($path_to_image_directory . $filename);
} else
if (preg_match('/[.](gif)$/', $filename)) {
$myimage = imagecreatefromgif($path_to_image_directory . $filename);
} else
if (preg_match('/[.](png)$/', $filename)) {
$myimage = imagecreatefrompng($path_to_image_directory . $filename);
}
$dimension = getimagesize($myimage);
#$width = imagesx($myimage);
#$height = imagesy($myimage);
#$finalwidth = $final_width_of_image;
#$newyvalue = floor($height * ($finalwidth / $width));
$color = imagecreatetruecolor($final_width_of_image, $thumbheight);
imagecopyresampled($color, $myimage, 0, 0, 0, 0, $final_width_of_image, $thumbheight, $dimension[0], $dimension[1]);
if (!file_exists($path_to_thumbs_directory)) {
if (!mkdir($path_to_thumbs_directory)) {
die("There was a problem. Please try again!");
}
}
imagejpeg($color, $path_to_thumbs_directory . $filename);
$thumb = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
#$thumb .= '<br />Congratulations. Your file has been successfully uploaded, and a thumbnail has been created.';
# echo $thumb;
}
} //isset
?>pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: