Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$source_file = preg_replace("/(http:\/\/www.magicmurals.com)|(https:\/\/www.magicmurals.com)/", "/web/magicmurals/stage/var/cache/images/",$_GET['src']);
- $source_file = preg_replace("/(http:\/\/foo.magicmurals.com)|(https:\/\/w.magicmurals.com)/", "/web/magicmurals/stage/var/cache/images/",$_GET['src']);
- $source_file = $_GET['src'];
- $source_file = preg_replace("/(http:\/\/staging.magicmurals.com)|(https:\/\/www.magicmurals.com)/", "/web/magicmurals/prod",$_GET['src']);
- $grayscale = $_GET['g'];
- $vertical = $_GET['v'];
- $horizantal = $_GET['h'];
- $cartImage = $_GET['c'];
- $crop = $_GET['crop'];
- $sepia = $_GET['s'];
- $watermark = $_GET['wm'];
- $trg = $_GET['trg'];
- $resize = $_GET['resize'];
- //get file type
- $source_file_type = image_type_to_mime_type(exif_imagetype($source_file));
- $im = ImageCreateFromJpeg($source_file);
- if( $source_file_type == 'image/jpeg') $im = ImageCreateFromJpeg($source_file);
- if( $source_file_type == 'image/gif') $im = @imagecreatefromgif($source_file);
- if( $source_file_type == 'image/png') $im = @imagecreatefrompng($source_file);
- function grayscale(&$img) {
- $imggw = imagesx($img);
- $imggh = imagesy($img);
- for ($i=0; $i<$imggw; $i++){
- for ($j=0; $j<$imggh; $j++) {
- $rgb = ImageColorAt($img, $i, $j);
- $rr = ($rgb >> 16) & 0xFF;
- $gg = ($rgb >> 8) & 0xFF;
- $bb = $rgb & 0xFF;
- $g = round(($rr + $gg + $bb) / 3);
- $val = imagecolorallocate($img, $g, $g, $g);
- imagesetpixel ($img, $i, $j, $val);
- }
- }
- }
- function flipVertical(&$img) {
- $size_x = imagesx($img);
- $size_y = imagesy($img);
- $temp = imagecreatetruecolor($size_x, $size_y);
- $x = imagecopyresampled($temp, $img, 0, 0, 0, ($size_y-1), $size_x, $size_y, $size_x, 0-$size_y);
- if ($x) {
- $img = $temp;
- } else {
- die("Unable to flip image");
- }
- }
- function flipHorizontal(&$img) {
- $size_x = imagesx($img);
- $size_y = imagesy($img);
- $temp = imagecreatetruecolor($size_x, $size_y);
- $x = imagecopyresampled($temp, $img, 0, 0, ($size_x-1), 0, $size_x, $size_y, 0-$size_x, $size_y);
- if ($x) {
- $img = $temp;
- } else {
- die("Unable to flip image");
- }
- }
- function resizeCartImg(&$img) {
- $size_x = 248;
- $ratio = 248/imagesx($img);
- $size_y = imagesy($img)*$ratio;
- $temp = imagecreatetruecolor($size_x, $size_y);
- $x = imagecopyresampled($temp, $img, 0, 0, 0, 0, $size_x, $size_y, imagesx($img), imagesy($img));
- if ($x) {
- $img = $temp;
- } else {
- die("Unable to resize image");
- }
- }
- function resizeCropImg(&$img) {
- $size_x = 573;
- $ratio = 573/imagesx($img);
- $size_y = imagesy($img)*$ratio;
- $temp = imagecreatetruecolor($size_x, $size_y);
- $x = imagecopyresampled($temp, $img, 0, 0, 0, 0, $size_x, $size_y, imagesx($img), imagesy($img));
- if ($x) {
- $img = $temp;
- } else {
- die("Unable to resize image");
- }
- }
- function sepiaImg(&$img) {
- imagefilter($img,IMG_FILTER_GRAYSCALE);
- imagefilter($img,IMG_FILTER_COLORIZE,100,50,0);
- }
- function resizeImg(&$img) {
- $size_x = 573;
- $ratio = 573/imagesx($img);
- $size_y = imagesy($img)*$ratio;
- $temp = imagecreatetruecolor($size_x, $size_y);
- $x = imagecopyresampled($temp, $img, 0, 0, 0, 0, $size_x, $size_y, imagesx($img), imagesy($img));
- if ($x) {
- $img = $temp;
- } else {
- die("Unable to resize image");
- }
- }
- function watermarkImg(&$img) {
- // Open the watermark
- $watermark = new Imagick();
- $watermark->readImage("/web/magicmurals/prod/images/watermarkMM.png");
- $size_x = imagesx($img);
- $size_y = imagesy($img);
- $temp = imagecreatetruecolor($size_x, $size_y);
- $temp->compositeImage($watermark, imagick::COMPOSITE_OVER, (((($temp->getImageWidth()) - ($watermark->getImageWidth())))/2), (((($temp->getImageHeight()) - ($watermark->getImageHeight())))* .96));
- $x = imagecopyresampled($temp, $img, 0, 0, 0, 0, $size_x, $size_y, imagesx($img), imagesy($img));
- if ($x) {
- $img = $temp;
- } else {
- die("Unable to resize image");
- }
- }
- if($grayscale=="1")grayscale($im);
- if($vertical=="1")flipVertical($im);
- if($horizantal=="1")flipHorizontal($im);
- if($cartImage=="1")resizeCartImg($im);
- if($crop=="1")resizeCropImg($im);
- if($sepia=="1") sepiaImg($im);
- if($resize=="1") resizeImg($im);
- if($watermark=="10") watermarkImg($im);
- if ($watermark != '0') {
- $img_name = basename($_GET['src']);
- $strUnique = sprintf("%u", ip2long($_SERVER['REMOTE_ADDR'])) . floor(microtime(true));
- $file = "/web/magicmurals/prod/images/output-".$img_name.'_'.$strUnique."_".$_GET['s']."_".$_GET['trg']."_".$_GET['h']."_".$_GET['g'].".jpg";
- imagejpeg($im, $file);
- $img = new Imagick();
- $img->readImage($file);
- $watermark = new Imagick();
- $watermark->readImage("/web/magicmurals/prod/images/watermarkMM.png");
- $img->compositeImage($watermark, imagick::COMPOSITE_OVER, (((($img->getImageWidth()) - ($watermark->getImageWidth())))/2), (((($img->getImageHeight()) - ($watermark->getImageHeight())))* .96));
- header("Content-Type: image/" . $img->getImageFormat());
- echo $img;
- } else {
- header('Content-type: image/jpeg');
- imagejpeg($im);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement