Forum Moderators: coopster
<?php
ini_set('display_errors',0);
//error_reporting(E_ALL);
$max_width = 0;
$mam = isset($_GET['mam']) ? true : false;
$img = $_GET['img'];
$supplier_id = @$_GET['s'];
if($img == "no_image"){
switch( @$_GET['size'] )
{
case "small":
$type = "image/jpeg";
$filename = $_GET['img'];
$split = explode(".", $filename);
$filename = $split[0] ."_small";
break;
case "list":
$type = "image/jpeg";
$filename = $_GET['img'];
$split = explode(".", $filename);
$filename = $split[0] ."_list";
break;
case "detail":
$type = "image/jpeg";
$filename = $_GET['img'];
$split = explode(".", $filename);
$filename = $split[0] ."_detail";
break;
case "email":
$type = "image/jpeg";
$filename = $_GET['img'];
$split = explode(".", $filename);
$filename = $split[0] ."_email";
break;
}
$show_watermark = false;
$image = "part_images/" . $filename .".jpg";
}else{
if(!$mam){
$type = "image/jpeg";
switch( @$_GET['size'] )
{
case "small":
$show_watermark = false;
$max_width = 60;
$max_height = 60;
$image = !is_null($supplier_id) ? "part_images/". $supplier_id ."/". $img .".jpg" : "part_images/". $img;
break;
case "list":
$show_watermark = false;
$max_width = 160;
$max_height = 160;
$image = !is_null($supplier_id) ? "part_images/". $supplier_id ."/". $img .".jpg" : "part_images/". $img;
break;
case "detail":
$show_watermark = false;
$watermark = "images/watermark.png";
$max_width = 220;
$max_height = 220;
$image = !is_null($supplier_id) ? "part_images/". $supplier_id ."/". $img .".jpg" : "part_images/". $img;
break;
case "email":
$show_watermark = false;
$watermark = "images/watermark.png";
$max_width = 110;
$max_height = 110;
$image = !is_null($supplier_id) ? "part_images/". $supplier_id ."/". $img .".jpg" : "part_images/". $img;
break;
case "large":
$show_watermark = false;
$watermark = "images/watermark_large.png";
$max_width = 600;
$max_height = 600;
$image = !is_null($supplier_id) ? "part_images/". $supplier_id ."/". $img .".jpg" : "part_images/". $img;
break;
}
}else{
$filename = str_replace("__", "/", $img);
$ext = @strtolower($_GET['ext']);
$type = $ext=="jpg" ? "image/jpeg" : "image/gif";
$image_url = "http://www.example/acweb/images/";
switch( @$_GET['size'] )
{
case "small":
$show_watermark = false;
$max_width = 60;
$max_height = 60;
break;
case "list":
$show_watermark = false;
$max_width = 150;
$max_height = 150;
break;
case "detail":
$show_watermark = false;
$watermark = "images/watermark.png";
$max_width = 220;
$max_height = 220;
break;
case "multi":
$show_watermark = false;
$watermark = "images/watermark.png";
$max_width = 700;
$max_height = 240;
break;
case "email":
$show_watermark = false;
$watermark = "images/watermark.png";
$max_width = 110;
$max_height = 110;
break;
case "large":
$show_watermark = false;
$watermark = "images/watermark_large.png";
$max_width = 600;
$max_height = 600;
break;
}
$image = $image_url . $filename .".". $ext;
}
}
if($max_width>0){
//create image so we can do the resize
if($type=="image/jpeg"){
if(!$imgTmp = imagecreatefromjpeg($image)){
die();
}
}else{
if(!$imgTmp = imagecreatefromgif($image)){
die();
}
}
//get orginial file properties
list($orginialWidth, $orginialHeight) = getimagesize($image);
if($orginialWidth > $max_width || $orginialHeight > $max_height){
$deltaWidth = $orginialWidth - $max_width;
$deltaHeight = $orginialHeight - $max_height;
if($deltaHeight > $deltaWidth){
//scale by height
$scaleFactor = $max_height / $orginialHeight;
}else{
//scale by width
$scaleFactor = $max_width / $orginialWidth;
}
$newWidth = $orginialWidth * $scaleFactor;
$newHeight = $orginialHeight * $scaleFactor;
}else{
$newWidth = $orginialWidth;
$newHeight = $orginialHeight;
}
if($_GET['size']=="detail"){
$im2 = imagecreatetruecolor($max_width , $max_height);
}else{
$im2 = imagecreatetruecolor($max_width , $max_height);
}
imagefill($im2, 1, 1, imagecolorallocate($im2, 255, 255, 255));
//now resize the image
imagecopyresampled($im2, $imgTmp, (imagesx($im2)/2)-($newWidth/2), (imagesy($im2)/2)-($newHeight/2), 0 ,0, $newWidth, $newHeight, $orginialWidth, $orginialHeight);
imagedestroy($imgTmp);
}else{
if($type=="image/jpeg"){
$im2 = imagecreatefromjpeg($image);
}else{
$im2 = imagecreatefromgif($image);
}
}
if($show_watermark){
$im = imagecreatefrompng($watermark);
imagecopy($im2, $im, (imagesx($im2)/2)-(imagesx($im)/2), (imagesy($im2)/2)-(imagesy($im)/2), 0, 0, imagesx($im), imagesy($im));
}
imageinterlace($im2, 1);
header("Content-Type: $type");
if($type=="image/jpeg"){
imagejpeg($im2,NULL, 100);
}else{
imagegif($im2);
}
echo $image;
//imagedestroy($im);
imagedestroy($im2);
?>
ini_set('display_errors',0);
//error_reporting(E_ALL);
$image = !is_null($supplier_id) ? "part_images/". $supplier_id ."/". $img .".jpg" : "part_images/". $img;