$height){ $newwidth = 0; }else{ $newheight = 0; } } } // *********** if($newwidth == 0 && $newheight == 0){ echo "ERROR!!!!"; exit; }elseif($newwidth != 0 && $newheight == 0){ $ratio = $width / $newwidth; $newheight = $height / $ratio; }elseif($newwidth == 0 && $newheight != 0){ $ratio = $height / $newheight; $newwidth = $width / $ratio; }else{ // NOP } } /***/ if(isset($_GET['maxh']) || isset($_GET['maxb'])){ $maxwidth = 0; $maxheight = 0; $newwidth = 0; $newheight = 0; if(isset($_GET["maxh"])) { if(!intval($_GET['maxh'])){ echo "ERROR!!!!"; exit; }else{ $maxheight = $_GET['maxh']; } } if(isset($_GET["maxb"])) { if(!intval($_GET['maxb'])){ echo "ERROR!!!!"; exit; }else{ $maxwidth = $_GET['maxb']; } } /*if($width > $height){ $newwidth = $maxwidth; }else{*/ $newheight = $maxheight; //} // *********** $ratio = $height / $newheight; $newwidth = $width / $ratio; if($newwidth > $maxwidth){ $ratio = $newwidth / $maxwidth; $newheight = $newheight / $ratio; $newwidth = $maxwidth; } } header("Content-Type: '".$row['mime']."'"); // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromstring($row['content']); /* if($row['mime'] == "image/jpeg"){ $source = imagecreatefromjpeg($filename); }elseif($row['mime'] == "image/gif"){ $source = imagecreatefromgif($filename); }elseif($row['mime'] == "image/png" || $row['mime'] == "image/x-png"){ $source = imagecreatefrompng($filename); }else{ $source = imagecreatefromjpeg($filename); } */ // Resize /* echo('['.$width.']'); echo('['.$height.']'); echo('['.$newwidth.']'); echo('['.$newheight.']'); */ if(!isset($_GET['mode'])){ imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); }else{ if($_GET['mode'] == 'crop'){ // linear scale first imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Crop if($width > $height){ $offset = floor(($newwidth - $_GET['b']) / 2); $stop = $offset + $_GET['b']; $thumbt = $thumb; $thumb = imagecreatetruecolor($_GET['b'], $_GET['h']); imagecopyresampled($thumb, $thumbt, 0, 0, $offset, 0, $_GET['b'], $_GET['h'], $stop, $newheight); }else{ $offset = floor(($newheight - $_GET['h']) / 2); $stop = $offset + $_GET['h']; $thumbt = $thumb; $thumb = imagecreatetruecolor($_GET['b'], $_GET['h']); imagecopyresampled($thumb, $thumbt, 0, 0, 0, $offset, $_GET['b'], $_GET['h'], $newwidth, $_GET['h']); } } } /* echo('['.$offset.']'); echo('['.$stop.']'); exit; */ // Output header('Content-Control: cache'); header('Content-type: '.$row['mime'].''); header('Content-Disposition: attachment; filename="'.$row['filename'].'"'); if($row['mime'] == "image/jpeg"){ imagejpeg($thumb); imagejpeg($thumb,$filewrite); }elseif($row['mime'] == "image/gif"){ imagegif($thumb); imagegif($thumb,$filewrite); }elseif($row['mime'] == "image/png" || $row['mime'] == "image/x-png"){ imagepng($thumb); imagepng($thumb,$filewrite); }else{ imagejpeg($thumb); imagejpeg($thumb,$filewrite); } imagedestroy($thumb); } } } function getJPEGImageXY($data) { $soi = unpack('nmagic/nmarker', $data); if ($soi['magic'] != 0xFFD8) return false; $marker = $soi['marker']; $data = substr($data, 4); $done = false; while(1) { if (strlen($data) === 0) return false; switch($marker) { case 0xFFC0: $info = unpack('nlength/Cprecision/nY/nX', $data); return array($info['X'], $info['Y']); break; default: $info = unpack('nlength', $data); $data = substr($data, $info['length']); $info = unpack('nmarker', $data); $marker = $info['marker']; $data = substr($data, 2); break; } } } ?>