I’m using the code below to re-size images in php. Its inside a function. It executes if $imgSource is true. If something in this failed, I’d like it to return false (maybe imagecopyresampled failed or something else failed). Thing is, where do I put the return true or false statement. Right now it’ll return false even if things went ok or not. Do I have to write if statements for all that’s in there. Can u please suggest a good way to do this.
if ($imgSource)
{
list($width,$height)=getimagesize($thisImage);
$dispImageWidth=500;
$dispImageHeight=($height/$width)*$dispImageWidth;
$tempDisplayImage=imagecreatetruecolor($dispImageWidth,$dispImageHeight);
$thumbImageWidth=250;
$thumbImageHeight=($height/$width)*$thumbImageWidth;
$tempThumbImage=imagecreatetruecolor($thumbImageWidth,$thumbImageHeight);
imagecopyresampled($tempDisplayImage,$imgSource,0,0,0,0,$dispImageWidth,$dispImageHeight,$width,$height);
imagecopyresampled($tempThumbImage,$imgSource,0,0,0,0,$thumbImageWidth,$thumbImageHeight,$width,$height);
$displayImageTarget = $thisPath.'disp_'.$fileName;
$thumbImageTarget = $thisPath.'thumb_'.$fileName;
imagejpeg($tempDisplayImage,$displayImageTarget,100);
imagejpeg($tempThumbImage,$thumbImageTarget,100);
imagedestroy($imgSource);
imagedestroy($tempDisplayImage);
imagedestroy($tempThumbImage);
unlink($thisImage);
//Where do I put the return true or false?
}
Do some thing like
if(! your statement ) return false;CODE
if ($imgSource)
{
if you only want to check the unset
just do
return unlink($thisImage);unlink Returns TRUE on success or FALSE on failure. see the php manual