PHP Academy Project 3

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

PHP Academy Project 3

Postby gazza7 » Sun Oct 03, 2010 10:42 pm

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.
gazza7
 
Posts: 5
Joined: Wed Feb 27, 2008 12:57 pm

Postby NoNameWill » Sun Oct 03, 2010 11:30 pm

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


spellcheck :lol: change $source_hieght to $source_height. [/b]
NoNameWill
 
Posts: 18
Joined: Mon Sep 20, 2010 10:40 pm
Location: Seattle,WA

Postby gazza7 » Mon Oct 04, 2010 5:26 pm

Thanks for that, it work fine, trust me not to spell check :oops: .
gazza7
 
Posts: 5
Joined: Wed Feb 27, 2008 12:57 pm

Postby NoNameWill » Sat Oct 09, 2010 7:00 pm

You're welcome. Not that I ever do that. :wink:
NoNameWill
 
Posts: 18
Joined: Mon Sep 20, 2010 10:40 pm
Location: Seattle,WA


Return to Programming

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest