array("prodid"=>0,"priority"=>1), "form"=>array("prodid"=>1,"priority"=>1), "ampenhpri"=>array("prodid"=>1,"priority"=>1), "ampenhsec"=>array("prodid"=>1,"priority"=>2) ); // Size defaults based on loc. loc 0==product detail page // $sizeDefaults=array( // 0=>array(1=>array("h"=>"250","w"=>"200"),2=>array("h"=>"25","w"=>"20")) // ); // Product ID and new size // (Image with prodid "0" is the "Image not available" product) $prodid = (isset($_GET['p'])&&is_numeric($_GET['p']))?$_GET['p']:0; // If priority is specified, set to that. Otherwise, set to 1 $priority = (isset($_GET['r'])&&is_numeric($_GET['r']))?$_GET['r']:1; // If priority is greater than 4, set priority to 1 $priority = ($priority>5)?1:$priority; // If loc is specified, set the default image accordingly $loc = (isset($_GET['loc'])&&array_key_exists($_GET['loc'],$locDefaults))?$_GET['loc']:0; // If measure is not specified or is non-numeric, set to 0 (original size) // Measurement is provided in pixels $measure = (isset($_GET['m'])&&is_numeric($_GET['m']))?$_GET['m']:0; $dimension = ($measure!=0&&isset($_GET['d'])&&(stripos("x".$_GET['d'],"w")==true||stripos("x".$_GET['d'],"h")==true))?$_GET['d']:""; $mimes=array("jpeg"=>"jpeg","png"=>"png","pjpeg"=>"jpeg","x-png"=>"png"); // Connect to MySql require_once "../../includes/enh/mysql.inc.php"; $GLOBALS['dbw'] = new PDO(sprintf('mysql:dbname=%s;host=%s;',$db,$host),$user,$pass, array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY=>true)); $GLOBALS['dbr'] = new PDO(sprintf('mysql:dbname=%s;host=%s;',$db,$host),$ruser,$rpass, array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY=>true)); // echo $locDefaults[$loc]['prodid']." - ".$locDefaults[$loc]['priority']; // exit; //get image from database $q=sprintf("SELECT `enh_img_raw`.`bin_img` AS `img`,`enh_img_info`.`width` AS `width`,`enh_img_info`.`height` AS `height`,`enh_img_info`.`mime` AS `mime` FROM `enh_img_raw`, `enh_img_info` WHERE `enh_img_info`.`prodid` = %s AND `enh_img_info`.`img_id`=`enh_img_raw`.`img_id` AND `enh_img_info`.`priority`=%s",$prodid,$priority); $imgR = $GLOBALS['dbr']->query($q); $imgData = $imgR->fetch(PDO::FETCH_ASSOC); if(empty($imgData)){ // Get the default image from the database $q=sprintf("SELECT `enh_img_raw`.`bin_img` AS `img`,`enh_img_info`.`width` AS `width`,`enh_img_info`.`height` AS `height`,`enh_img_info`.`mime` AS `mime` FROM `enh_img_raw`, `enh_img_info` WHERE `enh_img_info`.`prodid` = %s AND `enh_img_info`.`img_id`=`enh_img_raw`.`img_id` AND `enh_img_info`.`priority`=%s",$locDefaults[$loc]['prodid'],$locDefaults[$loc]['priority']); $imgR = $GLOBALS['dbr']->query($q); $imgData = $imgR->fetch(PDO::FETCH_ASSOC); } $imgOrig = $imgData['img']; $imgOrigMeasure['width'] = $imgData['width']; $imgOrigMeasure['height'] = $imgData['height']; $imgRatio = ($imgOrigMeasure['width']/$imgOrigMeasure['height']); $imgMimeType = $mimes[substr($imgData['mime'],strpos($imgData['mime'],"/")+1)]; switch($dimension){ case "": $dimension=""; break; case "w": $dimension="width"; $odimension="height"; if($imgOrigMeasure['width']>$imgOrigMeasure['height']) $op=($imgRatio>=1)?"bcdiv":"bcmul"; else $op=($imgRatio>=1)?"bcmul":"bcdiv"; break; case "h": $dimension="height"; $odimension="width"; if($imgOrigMeasure['width']>$imgOrigMeasure['height']) $op=($imgRatio>=1)?"bcmul":"bcdiv"; else $op=($imgRatio>=1)?"bcdiv":"bcmul"; break; } // Get new sizes //if $measure is 0 or $dimension is empty //or if $measure is larger than orig measurement, default to orig measurement if($measure==0||$dimension==""||$measure >= $imgOrigMeasure[$dimension]) { $newMeasure['width']=$imgOrigMeasure['width']; $newMeasure['height']=$imgOrigMeasure['height']; } //else, set new measure to the new measurements else { $newMeasure[$dimension]=$measure; $newMeasure[$odimension]=round($op($measure,$imgRatio,5)); } // Load $thumb = imagecreatetruecolor($newMeasure['width'], $newMeasure['height']); // $source = imagecreatetruecolor($newMeasure['width'], $newMeasure['height']); // imagealphablending($thumb, 1); $imgOrig = base64_decode($imgOrig); $source = imagecreatefromstring($imgOrig); // $thumb = imagecreatefromstring($imgOrig); // imagealphablending($source, 1); // setting alpha blending on // imagesavealpha($source, 0); imagealphablending($thumb, false); // setting alpha blending on imagesavealpha($thumb, true); // Resize // imagecopyresized($thumb, $source, 0, 0, 0, 0, $newMeasure['width'], $newMeasure['height'], $imgOrigMeasure['width'], $imgOrigMeasure['height']); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newMeasure['width'], $newMeasure['height'], $imgOrigMeasure['width'], $imgOrigMeasure['height']); imagealphablending($source, false); imagesavealpha($source, true); // Output header("Pragma: no-cache"); header("Cache-Control: no-store,no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: post-check=0, pre-check=0", false); if($dl){ header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"cal.".date("Y-m-d").".xls\""); header('Content-Transfer-Encoding: binary'); } else header("Content-type: image/png",true);// Content type switch($imgMimeType){ case "png": imagepng($thumb,null,8); break; case "jpeg": imagejpeg($thumb); break; default: echo "There was an error"; } exit; // imagejpeg($thumb);//image imagepng($thumb);//image