PDA

View Full Version : htaccess help


dawhoo
03-24-2006, 02:47 PM
I have been using the same method to watermark my images for a very long time and I've used in on several different hosting companies. I just moved to BLuehost and cannot get my combination to work anymore.

Filed a ticket, but they won't provide support for this, which is understandable. However, this works on 6 different servers and not working seems to be unique to Bluehost, which isn't understandable, since I was told mod rewrite is installed and working properly.

Here's the htaccess file

RewriteEngine on
RewriteRule ^(.*)\.jpg /home/12345678(first 8 letters of domain)/public_html/watermark/image.php?%{REQUEST_FILENAME}


SetEnvIfNoCase Referer "^http://www.follywaves.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://follywaves.com/" locally_linked=1
SetEnvIf Referer "^$" locally_linked=1
<FilesMatch "\.(gif|png|jpeg|jpg)$">
Order Allow,Deny
Allow from env=locally_linked
</FilesMatch>

And here's the file it calls.

<?php
//watermark program
//Show that a jpeg image is going to be returned
//echo $QUERY_STRING;
//exit;
header("Content-type: image/jpeg");

//File names
$wmark='watermark.png';
$wmarks='watermark_s.png';
$noimg='noimg.png';
$mimage=$QUERY_STRING;

// mod to display default image instead of 404
if (file_exists($QUERY_STRING)) {
//echo "The file $QUERY_STRING exists";

//Loading
$watermark_img = imagecreatefrompng($wmark);
$watermarks_img = imagecreatefrompng($wmarks);

$wmrk_size = getimagesize($wmark);
$wmrks_size = getimagesize($wmarks);

$main_img = imagecreatefromjpeg($mimage);
//ImageAlphaBlending($main_image, true);

//Merge the 2 buffers
//The figure "300" can be changed to any figure suitable for your situation.

if (ImageSX($main_img) > 300) {
$posx = (ImageSX($main_img) - ImageSX($watermark_img))/4;
$posy = (ImageSY($main_img) - ImageSY($watermark_img));
imagecopy($main_img, $watermark_img, $posx, $posy, 0, 0, $wmrk_size[0], $wmrk_size[1]);
}else{
$posxs = (ImageSX($main_img) - ImageSX($watermarks_img))/4;
$posys = (ImageSY($main_img) - ImageSY($watermarks_img));
imagecopy($main_img, $watermarks_img, $posxs, $posys, 0, 0, $wmrks_size[0], $wmrks_size[1]);
}

//Output file to browser
imagejpeg($main_img);
imagedestroy($watermark_img);
imagedestroy($watermarks_img);
imagedestroy($main_img);

} else {
//echo "The file $QUERY_STRING does not exist";

//Loading
$noimg_show = imagecreatefrompng($noimg);

//Output file to browser
imagejpeg($noimg_show);
imagedestroy($noimg_show);

}
?>


I'm stumped

alligosh
03-24-2006, 07:42 PM
Try checking the error logs in the watermark directory:

[24-Mar-2006 08:27:55] PHP Warning: imagecreatefrompng(noimg.png): failed to open stream: No such file or directory in /home/follywav/public_html/watermark/image.php on line 51
[24-Mar-2006 08:27:55] PHP Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/follywav/public_html/watermark/image.php on line 54
[24-Mar-2006 08:27:55] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/follywav/public_html/watermark/image.php on line 55


personal guess is that it isn't the .htaccess that has an issue, but the script it calls. From the errors, it sounds like you don't have the file noimg.png available (wrong path, not on the server, etc.

Of course, that is a pure guess without actually troubleshooting your stuff.

dawhoo
03-25-2006, 01:30 PM
Changed the code - didn't help.

<?php
//watermark program
//Show that a jpeg image is going to be returned
//echo $QUERY_STRING;
//exit;
header("Content-type: image/jpeg");

//File names
$wmark='watermark.png';
$wmarks='watermark_s.png';
$mimage=$QUERY_STRING;

//Loading
$watermark_img = imagecreatefrompng($wmark);
$watermarks_img = imagecreatefrompng($wmarks);

$wmrk_size = getimagesize($wmark);
$wmrks_size = getimagesize($wmarks);

$main_img = imagecreatefromjpeg($mimage);
//ImageAlphaBlending($main_image, true);

//Merge the 2 buffers
//The figure "300" can be changed to any figure suitable for your situation.

if (ImageSX($main_img) > 300) {
$posx = (ImageSX($main_img) - ImageSX($watermark_img))/2;
$posy = (ImageSY($main_img) - ImageSY($watermark_img))/2;
imagecopy($main_img, $watermark_img, $posx, $posy, 0, 0, $wmrk_size[0], $wmrk_size[1]);

}else{
$posxs = (ImageSX($main_img) - ImageSX($watermarks_img))/2;
$posys = (ImageSY($main_img) - ImageSY($watermarks_img))/2;
imagecopy($main_img, $watermarks_img, $posxs, $posys, 0, 0, $wmrks_size[0], $wmrks_size[1]);

}

//Output file to browser
imagejpeg($main_img);
imagedestroy($watermark_img);
imagedestroy($watermarks_img);
imagedestroy($main_img);
?>

Produces:
[25-Mar-2006 14:33:39] PHP Warning: imagesx(): supplied argument is not a valid Image resource in /home/follywav/public_html/watermark/image.php on line 26
[25-Mar-2006 14:33:39] PHP Warning: imagesx(): supplied argument is not a valid Image resource in /home/follywav/public_html/watermark/image.php on line 32
[25-Mar-2006 14:33:39] PHP Warning: imagesy(): supplied argument is not a valid Image resource in /home/follywav/public_html/watermark/image.php on line 33
[25-Mar-2006 14:33:39] PHP Warning: imagecopy(): supplied argument is not a valid Image resource in /home/follywav/public_html/watermark/image.php on line 34
[25-Mar-2006 14:33:39] PHP Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/follywav/public_html/watermark/image.php on line 39
[25-Mar-2006 14:33:39] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/follywav/public_html/watermark/image.php on line 42






I tried several other watermark PHP/htaccess combinations. none work here, but they do work on hostfolks and powweb. I thought they required GD which shows as GD version 2.0.28

All my other htaccess files do work on BLuehost, they didn't work at GoDaddy, so there's always a trade off. If I can only have one, I'd rather be able to stop hotlinking on a per-folder basis, which I can do with htaccess here. BUt I sure would like to be able to do both.

If someone has a suggestion for on-the-fly watermarking that will work with the bluehost setup, please let me know.

dawhoo
04-02-2006, 05:07 PM
I have tried 3 more methods to watermark and none of them work. It doesn't seem to matter if I use GD or ImageMajik, I always have the same results: the 'red X' or 500 errors.

Is there something different that Bluehost does/doesn't have, that iPower, HostFolks and PowWeb do, which may be the root of this issue?

atomicnuke
04-03-2006, 09:50 PM
I watermark with GD and haven't had problems, so it isn't bluehost.

dawhoo
04-05-2006, 07:01 PM
I watermark with GD and haven't had problems, so it isn't bluehost.

what are you using then? I've tried 11 different htaccess and php combinations now and they either don't work or cause Server 500 errors. Not a single one works at all.

If the script works on five different hosting companies, but not here. The only other place I can't get the the htaccess to work is GoDaddy.

The first code in the first post works at
iPower
PowWeb
Hostfolks
Doteasy
Lypha

Could this be a setting in the php.ini file I should adjust? Safe mode maybe? As I see it, that's about the only thing different - lots of control here.

dawhoo
04-16-2006, 12:06 PM
OK, I had a few suggestions and some people sent me a few watermark files, but I'm talking about using a watermark from an image - not a font. I can write over image files with font based 'watermarks', but I can't get any watermark, that watermarks from an image to work.

Each time I try to use an image watermark, it takes down my whole site for about 5 minutes with a 500 error.

Automic..., you going to write back about what you actually got working? I've used 24 different combinations and scripts and STILL I get nothing other than taking down the server for about 5 minutes with 500 errors. I'll keep trying until I break something.

atomicnuke
04-24-2006, 02:23 PM
Sorry I've been gone, not sure if I can really help, my watermarking isn't through .htaccess it is through php. This is from a site that I started and didn't finish due to other projects that needed attention first. Sample (http://www.ilovetaffy.com/final/profile.php?username=tester) If you click the smaller thumbnail, it'll show the enlarged version with the simple water mark using another image (http://www.ilovetaffy.com/pics/users/watermark.jpg). So I know it is possible, just not sure with the method you are trying.

Sai
04-24-2006, 03:29 PM
what's watermark? is that like putting your logo or text on a picture...
well i put logo on all my photos in a folder... it's about 300 photos and i just did it with one simple click...

there's a feature in photoshop (if you have it) to batchly watermark or add logo to all your image within a folder. it's all automatic.

that's what i did. 1 click in photoshop, upload to my site and im done. no need to codes or anything. you can also resize image in batch with photoshop

atomicnuke
04-24-2006, 03:33 PM
Yeah, but this is for photos other people upload, so it is watermarked when they upload to your site. Your method is for watermarking images then uploading them to the site, not efficient for user uploads.

Sai
04-24-2006, 03:44 PM
oh i see, so it's for other users...