Batch folder of images into grayscale using php
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. Script is running without visible error but no images are being created. 

    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);
    }
Batch folder of images into grayscale using php
===

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. Script is running without visible error but no images are being created. 

    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);
    }