Last active
October 15, 2016 06:55
-
-
Save cimmwolf/c927eb1d5db5e3914132aaae3b3781c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author: Denis Beliaev | |
*/ | |
$matches = []; | |
if (preg_match('#^(.*?)@(\d+|-)x(\d+|-)\.(gif|jpe?g|png)$#', $_SERVER['REQUEST_URI'], $matches)) { | |
if (($newW = $matches[2]) == '-') | |
$newW = -1; | |
if (($newH = $matches[3]) == '-') | |
$newH = -1; | |
$filePath = __DIR__ . $matches[1] . '.' . $matches[4]; | |
switch ($matches[4]) { | |
case 'gif': | |
header('Content-Type: image/gif'); | |
break; | |
case 'jpg': | |
header('Content-Type: image/jpeg'); | |
break; | |
case 'jpeg': | |
header('Content-Type: image/jpeg'); | |
break; | |
case 'png': | |
header('Content-Type: image/png'); | |
$image = imagecreatefrompng($filePath); | |
$image = imagescale($image, $newW, $newH); | |
imagealphablending($image, true); | |
imagesavealpha($image, true); | |
imagepng($image); | |
break; | |
} | |
if (!isset($image)) { | |
$image = imagecreatefromjpeg($filePath); | |
$image = imagescale($image, $newW, $newH); | |
imagejpeg($image); | |
} | |
imagedestroy($image); | |
} else | |
return false; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment