Skip to content

Instantly share code, notes, and snippets.

@Chrissy
Created February 24, 2011 04:30
Show Gist options
  • Save Chrissy/841753 to your computer and use it in GitHub Desktop.
Save Chrissy/841753 to your computer and use it in GitHub Desktop.
here is the htaccess file. my rewriterule is at the bottom. also included watermark script using GD. Gist is determined to put the php file first, though you may or may not even have to look at this. the htacces file is below it.
### 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/(.*) $1/workspace/scripts/watermark.php?src=workspace/images/$2
</IfModule>
######
<?php
//get stuff
$src = $_SERVER['DOCUMENT_ROOT'].'/'.$_GET['src'];
$watermarkSRC = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/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, "", 100);
imagedestroy($image);
imagedestroy($watermark);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment