Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Get image
- $handle = fopen($_GET['url'], 'rb');
- $img = new Imagick();
- $img->readImageFile($handle);
- $orgWidth = $_GET['width'];
- $orgHeight = $_GET['height'];
- // Do math
- $width = $orgWidth;
- $height = $orgHeight;
- $wah = $width > $height;
- $r;
- if(!$wah)
- {
- $r = $img->width/$img->height;
- $width = $height*$r;
- }
- else
- {
- $r = $img->height/$img->width;
- $height = $width*$r;
- }
- // Resize iamge
- $img->resizeImage($width, $height, 0, 0);
- // Crop image
- $offsetX = ($img->width - $orgWidth)/2;
- $offsetY = ($img->height - $orgHeight)/2;
- $img->cropImage($orgWidth, $orgHeight, $offsetX, $offsetY);
- echo '<img src="data:image/jpg;base64,'.base64_encode($img->getImageBlob()).'" alt="" />';
- // $img->writeImage('images/foo.jpg'); om op te slaan
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement