-
[PHP] GD Image Help
Hey,
I made this code, but it only echos one image and there is 7 images in that directory... but it only echos one image resized, how would I fix the code to echo all 7 one after the other??
CODE:
PHP Code:
<?php
// Generates thumnail graphic
function doGD($path,$jpg) {
$jpgFile = "$path/$jpg";
$width = 120;
list($width_orig, $height_orig) = getimagesize($jpgFile);
$height = (int) (($width / $width_orig) * $height_orig);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($jpgFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, null, 60);
imagedestroy($image_p);
}
//define the path as relative
$path = "test/";
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
//running the while loop
while ($file = readdir($dir_handle))
{
if($file == "." || $file == ".."){
$file = "";
}else{
header('Content-type: image/jpeg');
doGD("$path","$file");
}
}
//closing the directory
closedir($dir_handle);
?>
Dan
-
ImageJPG outputs the picture.
What you'll have to do is have 2 files.
doGD.php
PHP Code:
if(!$_REQUEST['path'] || !$_REQUEST['jpg']) exit();
$jpgFile = $_REQUEST['path']."/".$_REQUEST['jpg'];
$width = 120;
list($width_orig, $height_orig) = getimagesize($jpgFile);
$height = (int) (($width / $width_orig) * $height_orig);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($jpgFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
header('Content-type: image/jpeg');
imagejpeg($image_p, null, 60);
imagedestroy($image_p);
Main Code
PHP Code:
//define the path as relative
$path = "test/";
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
//running the while loop
while ($file = readdir($dir_handle))
{
if($file != "." && $file != ".."){
echo "<img src=\"doGD.php?path=".$path."&jpg=".$file." />";
}
}
//closing the directory
closedir($dir_handle);
-
EDIT:
Sorry the ticko was looking at the wrong file!!!
I have tryed your script but its echoing 4 boxes with no images in them just like a page in a little box
Dan
-
FIXED Thanks for your help!
-
Need some more, help!!
How would I add this? I want to add a watermark to at a 45 degree angle
PHP Code:
$black = imagecolorallocate($imgrdg, 0, 0, 0);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add the text
imagettftext($imgrdg, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagejpeg($imgrdg);
imagedestroy($imgrdg);
Dan