Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PHP Academy Project 3

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
gazza7



Joined: Wed Feb 27, 2008 12:57 pm
Posts: 5

PostPosted: Sun Oct 03, 2010 11:42 pm    Post subject: PHP Academy Project 3 Reply with quote

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
View user's profile Send private message
NoNameWill



Joined: Mon Sep 20, 2010 11:40 pm
Posts: 18
Location: Seattle,WA

PostPosted: Mon Oct 04, 2010 12:30 am    Post subject: Reply with quote

Code:
imagecopyresampled($to, $from, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $source_width, $source_hieght);


spellcheck Laughing change $source_hieght to $source_height. [/b]
Back to top
View user's profile Send private message
gazza7



Joined: Wed Feb 27, 2008 12:57 pm
Posts: 5

PostPosted: Mon Oct 04, 2010 6:26 pm    Post subject: Reply with quote

Thanks for that, it work fine, trust me not to spell check Embarassed .
Back to top
View user's profile Send private message
NoNameWill



Joined: Mon Sep 20, 2010 11:40 pm
Posts: 18
Location: Seattle,WA

PostPosted: Sat Oct 09, 2010 8:00 pm    Post subject: Reply with quote

You're welcome. Not that I ever do that. Wink
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
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
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast