-
-
Save chrisdickinson/841796 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### Symphony 2.0.x ### | |
Options +FollowSymlinks -Indexes | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteBase / | |
### DO NOT APPLY RULES WHEN REQUESTING "favicon.ico" | |
RewriteCond %{REQUEST_FILENAME} favicon.ico [NC] | |
RewriteRule .* - [S=14] | |
### IMAGE RULES | |
RewriteRule ^image\/(.+\.(jpg|gif|jpeg|png|bmp))$ extensions/jit_image_manipulation/lib/image.php?param=$1 [L,NC] | |
RewriteCond %{REQUEST_URI} ^/images/cached | |
### CHECK FOR TRAILING SLASH - Will ignore files | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_URI} !/$ | |
RewriteCond %{REQUEST_URI} !(.*)/$ | |
RewriteRule ^(.*)$ $1/ [L,R=301] | |
### ADMIN REWRITE | |
RewriteRule ^symphony\/?$ index.php?mode=administration&%{QUERY_STRING} [NC,L] | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^symphony(\/(.*\/?))?$ index.php?symphony-page=$1&mode=administration&%{QUERY_STRING} [NC,L] | |
### FRONTEND REWRITE - Will ignore files and folders | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*\/?)$ index.php?symphony-page=$1&%{QUERY_STRING} [L] | |
RewriteRule ^workspace/images/(.*) workspace/scripts/watermark.php?src=$1 | |
</IfModule> | |
###### |
This file contains hidden or 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 | |
//get stuff | |
$working_dir = 'workspace/images'; | |
$target_dir = 'workspace/resized'; | |
$filename = $_GET['src']; | |
$src = $_SERVER['DOCUMENT_ROOT'].'/'.$working_dir.'/'.$_GET['src']; | |
$target = $_SERVER['DOCUMENT_ROOT'].'/'.$target_dir.'/'.$_GET['src']; | |
if(file_exists($target)) { | |
header("Location: ${target_dir}/${filename}", true, 301); | |
} else { | |
$watermarkSRC = $_SERVER['DOCUMENT_ROOT'].'/workspace/static_files/watermark.png'; | |
header('Content-type: image/jpeg'); | |
//create watermark | |
$watermark = imagecreatefrompng($watermarkSRC); | |
//wm dimensions | |
$watermark_width = imagesx($watermark); | |
$watermark_height = imagesy($watermark); | |
$image = imagecreatetruecolor($watermark_width, $watermark_height); | |
//border | |
$border=40; // Change the value to adjust width | |
//some crappy logic | |
if(strpos($src,'.gif') !== false) { | |
$image = imagecreatefromgif($src); | |
} | |
elseif(strpos($src,'.jpeg') !== false || strpos($src,'.jpg') !== false) { | |
$image = imagecreatefromjpeg($src); | |
} | |
elseif(strpos($src,'.png') !== false) { | |
$image = imagecreatefrompng($src); | |
} | |
else { | |
exit("Your image is not a gif, jpeg or png image. Sorry."); | |
} | |
//image dimensions | |
$width=ImageSx($image); | |
$height=ImageSy($image); | |
//lets make a border | |
$img_adj_height=$height+$border; | |
$square=imagecreatetruecolor($width,$img_adj_height); | |
//border + image | |
imagecopyresampled($square, $image, 0, 0, 0, 0, $width, $img_adj_height, $width, $img_adj_height); | |
//watermark placement | |
$dest_x = $width - $watermark_width - 5; | |
$dest_y = $img_adj_height - $watermark_height - 5; | |
//border + watermark | |
imagecolortransparent($watermark,imagecolorat($watermark,0,0)); | |
imagecopyresampled($square, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $watermark_width, $watermark_height); | |
//wrap up | |
imagejpeg($square, $target, 100); | |
imagedestroy($image); | |
imagedestroy($watermark); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment