This was created for my job, but I want to see what everyone's opinion is.
This will be used as part of a cron job to resize images for rss feeds that will be produced for a CMS we use called Carma
/**
* @param string $file_path path to photo set
* @param string $carma_path path to carma cms
* @param string $new_path new image path for rss
* @param integer $active date image was activated in carma
* @param integer $max max image size of rss image
*/
function rss_image_create($file_path, $carma_path, $new_path, $active, $max)
{
$old_path = $carma_path.$file_path."/";
$old = $old_path."/sample.jpg";
$picture = $new_path."/".$active.".jpg";
copy($old, $picture);
$src_img=ImagecreateFromJpeg($picture);
$oh = imagesy($src_img); # original height
$ow = imagesx($src_img); # original width
$new_h = $oh;
$new_w = $ow;
if($oh > $max || $ow > $max)
{
$r = $oh/$ow;
$new_h = ($oh > $ow) ? $max : $max*$r;
$new_w = $new_h/$r;
}
$dst_img = ImageCreateTrueColor($new_w,$new_h);
ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, $ow, $oh);
ImageJpeg($dst_img, $picture, 100);
}
Please do not sugar coat flaws in the code or opinions in how I did it, if I did something wrong, please tell me.