Batch folder of images into grayscale using php

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-03-12T14:33:57Z Indexed on 2010/03/12 14:37 UTC
Read the original article Hit count: 324

Filed under:
|
|

Can anyone spot where I'm going wrong here. It should be creating grayscale copies of images in one folder and saving them in another folder. Could it be to do with the way im referencing the file locations. Folder permissions on both folders are 777

function grayscalecopy($targetfile, $outputfile){
$size = GetImageSize($targetfile);
$width = $size[1];
$height = $size[0];
$canvas = imagecreatetruecolor($width, $height);
$sourceimage = imagecreatefromjpeg($targetfile);
imagefilter($sourceimage, IMG_FILTER_GRAYSCALE);
imagecopy($canvas, $sourceimage, 0, 0, 0, 0, $width, $height);
imagejpeg($canvas, $outputfile, 95);
imagedestroy($sourceimage);
imagedestroy($canvas);
echo "Converted ".$targetfile." to grayscale as ".$outputfile." ".$width."x".$height."<br/>";
}

$serverfiles = glob("artworkimages/thumbs/*.*");
//$numbertocache = count($serverfiles);
$numbertocache = 10;
for ($i=0; $i<$numbertocache; $i++)
{
    $serverfilesshort=explode("/",$serverfiles[$i]);
    $serverfilesshort=$serverfilesshort[count($serverfilesshort)-1];
    grayscalecopy($serverfiles[$i], "artworkimages/thumbs/grays/".$serverfilesshort);
}

© Stack Overflow or respective owner

Related posts about php

Related posts about gd