Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hey guys. I want a script that will automatically create a thumbnail from an uploaded images. It's for my phpbb3 styles website and basically someone will upload a preview of their style which will be pretty big and then there will be a thumbnail that they click to enlarge it.
The majority of the script is done but I'm having a little problem. When it trys to create a thumbnail all I get is a smaller sized image full of black.
Here is the code I am currently using.
[b]This is function that will create a thumbnail based on parameters[/b]Code: Select all
function createThumbnail ($original, $thumbnail, $width, $height, $quality) {
list($width_orig, $height_orig) = getimagesize($original);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
}
else {
$height = ($width / $width_orig) * $height_orig;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($originial);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $thumbnail, $quality);
return;
}This is the code that is used to create the thumbnail
Code: Select all
$filetitle = $this->mainclass->database->userinput($_FILES['previewfile']['name']);
$filename = MD5(time() . $this->mainclass->phpbb->user->data["username"] . $_FILES['previewfile']['name'] . rand(5000, 15000)) . ".preview.jpg";
move_uploaded_file($_FILES['previewfile']['tmp_name'], $this->mainclass->serverpath . "/uploads/screenshots/" . $filename);
$this->createThumbnail($this->mainclass->serverpath . "/uploads/screenshots/" . $filename, $this->mainclass->serverpath . "/uploads/screenshots/thumbs/" . $filename, 150, 150, 100);A big thanks to everyone who trys to help me with this
Oh! and to anyone who wants to see the uploaded version that doesn't actually work, you can see it here
Mark
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]