function bResizeImage($oPIn, $oPOut, $iW, $iH) { // replace the image with the resized one global $goApp; $bSuccess = false; $rInImage = $rOutImage = false; WYImage::_allocateMemoryForImage($oPIn); if (!function_exists('imagejpeg')) { $goApp->log('bResizeImage: no GD lib with JPEG support installed'); return false; } if (strtolower($oPIn->sExtension()) == 'jpg') { if (!function_exists('imagecreatefromjpeg')) { $goApp->log('bResizeImage: no imagecreatefromjpeg function found'); return false; } else { $rInImage = @imagecreatefromjpeg($oPIn->sPath); } } else { if (strtolower($oPIn->sExtension()) == 'gif') { if (!function_exists('imagecreatefromgif')) { $goApp->log('bResizeImage: no imagecreatefromgif function found'); return false; } else { $rInImage = @imagecreatefromgif($oPIn->sPath); } } else { if (strtolower($oPIn->sExtension()) == 'png') { if (!function_exists('imagecreatefrompng')) { $goApp->log('bResizeImage: no imagecreatefrompng function found'); return false; } else { $rInImage = @imagecreatefrompng($oPIn->sPath); } } } } if (!$rInImage) { $goApp->log('bResizeImage: could not create image from ' . $oPIn->sPath); return false; } if (WYImage::bGD2Installed() && function_exists('imagecreatetruecolor')) { $rOutImage = @imagecreatetruecolor($iW, $iH); } else { if (function_exists('imagecreate')) { $rOutImage = @imagecreate($iW, $iH); } } if (!$rOutImage) { $goApp->log("bResizeImage: could not create output image of size {$iW}/{$iH}"); return false; } // preserve transparency if (strtolower($oPIn->sExtension()) == 'gif' || strtolower($oPIn->sExtension()) == 'png') { if (function_exists('imagecolortransparent') && function_exists('imagecolorallocatealpha') && function_exists('imagealphablending') && function_exists('imagesavealpha')) { @imagecolortransparent($rOutImage, @imagecolorallocatealpha($rOutImage, 0, 0, 0, 127)); @imagealphablending($rOutImage, false); @imagesavealpha($rOutImage, true); } else { $goApp->log('bResizeImage: unable to create transparent image'); } } if (WYImage::bGD2Installed() && function_exists('imagecopyresampled')) { $bSuccess = @imagecopyresampled($rOutImage, $rInImage, 0, 0, 0, 0, $iW, $iH, imagesx($rInImage), imagesy($rInImage)); } if (!$bSuccess && function_exists('imagecopyresized')) { $bSuccess = @imagecopyresized($rOutImage, $rInImage, 0, 0, 0, 0, $iW, $iH, imagesx($rInImage), imagesy($rInImage)); } if (!$bSuccess) { $goApp->log('bResizeImage: could not use imagecopyresampled or imagecopyresized'); return false; } unset($rInImage); // close input file switch (strtolower($oPIn->sExtension())) { // save image as the right file type case 'gif': $bSuccess = @imagegif($rOutImage, $oPOut->sPath); break; case 'png': $bSuccess = @imagepng($rOutImage, $oPOut->sPath, 9); break; case 'jpg': $bSuccess = @imagejpeg($rOutImage, $oPOut->sPath, 100); break; case 'jpeg': $bSuccess = @imagejpeg($rOutImage, $oPOut->sPath, 100); break; } chmod($oPIn->sPath, 0644); if (!$bSuccess) { $goApp->log("bResizeImage: could not create output image"); } return $bSuccess; }