Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Generate new size and save images to cache
- * @param $_GET['id'] id of image
- * @param $_GET['x'] new image width
- * @param $_GET['y'] new image height
- * @param $_GET['type'] 0-fit or 1-resize
- * @param $_GET['grey'] 0-nomral 1-greyscale
- */
- $id = preg_replace('#[^a-zA-Z0-9_/\.]#', '', $_GET['id']);
- $id = str_replace('..', '', $id);
- $x = (int) $_GET['x'];
- $y = (int) $_GET['y'];
- $type = (int) $_GET['type'];
- $filename = '/var/www/static/cache' . $id . '-' . $x . '-' . $y . '-' . $type . '.jpg';
- require_once 'Image/Transform.php';
- function chceckError($item)
- {
- if (PEAR::isError($item))
- {
- header("HTTP/1.0 404 Not Found");
- die();
- }
- }
- $it = Image_Transform::factory('GD');
- print_r($it);
- //chceckError($it);
- if (PEAR::isError($it->load('orginal/' . $id . '.jpg')))
- {
- chceckError($it->load('no_image.jpg'));
- }
- switch ($type)
- {
- case 0:
- if ($x == 0)
- $x = 10000;
- if ($y == 0)
- $y = 10000;
- chceckError($it->fit($x, $y));
- break;
- case 1:
- $ratio = $x / $y;
- $orginal_ratio = ($it->getImageWidth() / $it->getImageHeight());
- if ($orginal_ratio < $ratio)
- {
- chceckError($it->scaleByX($x));
- $starty = ($it->getNewImageHeight() - $y) / 3;
- chceckError($it->crop($x, $y, 0, $starty));
- }
- else
- {
- chceckError($it->scaleByY($y));
- $startx = ($it->getNewImageWidth() - $x) / 2;
- chceckError($it->crop($x, $y, $startx, 0));
- }
- break;
- case 2:
- break;
- default:
- header("HTTP/1.0 404 Not Found");
- die();
- }
- if ($_GET['grey'] == 1)
- chceckError($it->greyscale());
- $it2 = clone $it;
- chceckError($it2->save($filename));
- $time = gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT';
- header('Last-Modified: ' . $time);
- chceckError($it->display());
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement