Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once "SimpleImage.class.php";
- header("Content-Type: image/jpg");
- if(file_exists($_GET["src"]) === false) {
- header("HTTP/1.0 404 Not Found");
- die();
- }
- $existingSize = false;
- $maxWidth = +($_GET["width"]);
- $maxHeight = +($_GET["height"]);
- $filenameParts = pathinfo($_GET["src"]);
- $resizedNameTpl = "%s/%s_%ux%u.%s";
- $image = new SimpleImage($_GET["src"]);
- if($image->getWidth() > $image->getHeight()) {
- $ratio = $maxWidth / $image->getWidth();
- $newHeight = $image->getHeight() * $ratio;
- $resizedName = sprintf(
- $resizedNameTpl,
- $filenameParts["dirname"],
- $filenameParts["filename"],
- $maxWidth,
- $newHeight,
- $filenameParts["extension"]
- );
- $existingSize = file_exists($resizedName);
- if(!$existingSize) {
- $image->resizeToWidth($maxWidth);
- }
- }
- else {
- $ratio = $maxHeight / $image->getHeight();
- $newWidth = $image->getWidth() * $ratio;
- $resizedName = sprintf(
- $resizedNameTpl,
- $filenameParts["dirname"],
- $filenameParts["filename"],
- $newWidth,
- $maxHeight,
- $filenameParts["extension"]
- );
- $existingSize = file_exists($resizedName);
- if(!$existingSize) {
- $image->resizeToHeight($maxHeight);
- }
- }
- if(!$existingSize) {
- $image->save($resizedName);
- }
- echo file_get_contents($resizedName);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement