 |
Linux Format forums Help, discussion, magazine feedback and more
|
| View previous topic :: View next topic |
| Author |
Message |
gazza7
Joined: Wed Feb 27, 2008 12:57 pm Posts: 5
|
Posted: Sun Oct 03, 2010 11:42 pm Post subject: PHP Academy Project 3 |
|
|
After reading the chapter and keying in all the code, I have a problem that all of the thumbnails the code produces, are black.
I have tried messing with different parts of the code, but with no luck, Anyone got a idea why this is doing this. My code is has follows:-
<?php
function smart_resample($from, $to) {
$source_width = imagesx($from);
$source_height = imagesy($from);
$thumbnail_width = imagesx($to);
$thumbnail_height = imagesy($to);
imagecopyresampled($to, $from, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $source_width, $source_hieght);
}
$images=scandir("images");
$thumbnails=scandir("thumbnails");
$new_pics=array_diff($images,$thumbnails);
foreach ($new_pics as $pic) {
$image = imagecreatefromjpeg("images/$pic");
$source_width = imagesx($image);
$source_height = imagesy($image);
$ratio = $source_width / $source_height;
$height = 200 / $ratio;
$thumbnail =imagecreatetruecolor(200, $height);
smart_resample($image, $thumbnail);
imagejpeg($thumbnail, "thumbnails/$pic", 75);
}
//now loop again, printing out images and links
foreach($images as $image){
if($image==".")continue;
if($image=="..")continue;
//note that we have an <img> inside an <a>
echo"<a href=\"images/$image\"><img
src=\"thumbnails/$image\"/></a>";
}
?>
Any help will be much appreciated. |
|
| Back to top |
|
 |
NoNameWill
Joined: Mon Sep 20, 2010 11:40 pm Posts: 18 Location: Seattle,WA
|
Posted: Mon Oct 04, 2010 12:30 am Post subject: |
|
|
| Code: | | imagecopyresampled($to, $from, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $source_width, $source_hieght); |
spellcheck change $source_hieght to $source_height. [/b] |
|
| Back to top |
|
 |
gazza7
Joined: Wed Feb 27, 2008 12:57 pm Posts: 5
|
Posted: Mon Oct 04, 2010 6:26 pm Post subject: |
|
|
Thanks for that, it work fine, trust me not to spell check . |
|
| Back to top |
|
 |
NoNameWill
Joined: Mon Sep 20, 2010 11:40 pm Posts: 18 Location: Seattle,WA
|
Posted: Sat Oct 09, 2010 8:00 pm Post subject: |
|
|
You're welcome. Not that I ever do that.  |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|