error('400 Bad request', 'Path missing'); } $path = $GLOBALS['imagestore']['basedir'] . $_GET['path']; if (!file_exists($path)) { return $this->error('404 Not Found', 'File not found'); } if (!isset($_GET['w']) && !isset($_GET['h'])) { header('Content-type: image/jpeg'); header('Content-length: ' . filesize($path)); return readfile($path); } //resize $img = imagecreatefromjpeg($path); $oldX = $oldY = 0; $oldW = imagesx($img); $oldH = imagesy($img); if (isset($_GET['w']) && isset($_GET['h'])) { //max. bounding box respecting aspect ratio $newW = (int) $_GET['w']; $newH = (int) $_GET['h']; $rW = $oldW / $newW; $rH = $oldH / $newH; if ($rW > $rH) { $newOldW = intval($oldW / $rW * $rH); $oldX = $oldW / 2 - $newOldW / 2; $oldW = $newOldW; } else { $newOldH = intval($oldH / $rH * $rW); $oldY = $oldH / 2 - $newOldH / 2; $oldH = $newOldH; } } else if (isset($_GET['w'])) { $newW = (int) $_GET['w']; $newH = intval($newW / $oldW * $oldH); } else { $newH = (int) $_GET['h']; $newW = intval($newH / $oldH * $oldW); } $thumb = imagecreatetruecolor($newW, $newH); // Resize imagecopyresampled( $thumb, $img, 0, 0, $oldX, $oldY, $newW, $newH, $oldW, $oldH ); imagedestroy($img); header('Content-type: image/jpeg'); imagejpeg($thumb); imagedestroy($thumb); } } ?>