|
Subject
|
help on watermark php script
|
| | Posted by | fakestar (DH Dreamling) | | Posted on | 07/27/06 11:36 PM |
|
|
hi,
In my old server i was using a watermark script, just edit .htacess and put a .php file in a folder with .png image (the watermark) and all my pictures automatically were watermarked.
But i don't know how to make it works in dreamhost, i try everything i know, and nothing works. The script code is : http://www.activeunit.com/scripts/watermark.zip Could someone take a look in this script please?
Thanks!
|
|
|
|
Subject
|
Re: help on watermark php script
[re: fakestar]
|
| | Posted by | rlparker (DH Smarty Pants) | | Posted on | 07/28/06 01:08 AM |
|
|
I think the problem might that the default php configuration on Dreamhost is that PHP is running as CGI, and the variables that are manipulated in the beginning of the script grab environment/system variables that are different than the programmer expected when he wrote the script, though I'm not completely sure about that.
I'll have to look at it a bit further, as this is *not* my area of expertise (Simon, are you out there?), but I would think some minor changes to the beginning of the script might make it work.
--rlparker
Edited by rlparker on 07/28/06 02:17 AM (server time).
|
|
|
|
Subject
|
Re: help on watermark php script
[re: fakestar]
|
| | Posted by | netdcon (DH Regular) | | Posted on | 07/28/06 10:10 AM |
|
|
In reply to:
But i don't know how to make it works in dreamhost, i try everything i know, and nothing works. The script code is : http://www.activeunit.com/scripts/watermark.zip Could someone take a look in this script please?
Played with it; Don't think it's gonna work if you're using PHP as CGI. Not even sure how to revert PHP to Apache module, or even if it's offered. One thing for certain that I noticed is the path info is missing; i'd replace $dr=preg_replace('/modify\.php.+/', '', $_SERVER['PHP_SELF']); $filename=str_replace($dr, './', $_SERVER['PATH_INFO']);..with:
$dr=preg_replace('/modify\.php.+/', '', $_SERVER['PHP_SELF']); $filename=$_SERVER['DOCUMENT_ROOT'].$dr;..for starters.
Aside from that, there's a workaround for this that you can employ; simply modify this code to accept a query-string argument for a file name and keep all of the images in a fixed, separate directory that you have "access deny all" set in .htaccess; that way the PHP script should be able to access its files while the httpd won't allow it to be linked.
Alternatively, if you're feeling lazy and ya got a few $$ burning a hole in yer pocket and ya want my Rent-a-Coder account name, just lemme know.
|
|
|
|
Subject
|
Re: help on watermark php script
[re: netdcon]
|
| | Posted by | kchrist (DH Smarty Pants) | | Posted on | 07/28/06 10:55 AM |
|
|
Not even sure how to revert PHP to Apache module
To enable mod_php4 on a per directory basis, put this in .htaccess:
AddHandler application/x-httpd-php .php
-- If you want useful replies, ask smart questions.
|
|
|
|
Subject
|
Re: help on watermark php script
[re: netdcon]
|
| | Posted by | rlparker (DH Smarty Pants) | | Posted on | 07/28/06 01:32 PM |
|
|
Nedcon,
Pretty much the same experience I had, and I played around with it just a bit.
I was hopeful that doing a little creative substitution of variables in those lines woujld make for a simple fix but, as you noted, it's not *that* simple.
--rlparker
|
|
|
|
Subject
|
Re: help on watermark php script
[re: kchrist]
|
| | Posted by | fakestar (DH Dreamling) | | Posted on | 07/28/06 03:38 PM |
|
|
Thank you all for the quick responses.
kchrist, the line "AddHandler application/x-httpd-php .php" in .htacess did the trick, now the script is working.
Thank you :)
---------------------------
Edited: Now watermark script is working but i get errors uploading pictures in geeklog lol.
Edited by fakestar on 07/28/06 04:15 PM (server time).
|
|
|
|
Subject
|
Re: help on watermark php script
[re: netdcon]
|
| | Posted by | Atropos7 (DH DreamNinja) | | Posted on | 07/28/06 04:36 PM |
|
|
I was able to get it working with PHP 5 using:
$filename = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PATH_INFO']; One other thing I noticed is that it does not send the proper Content-Type header. Here is the fix for that: if ($image_format==1) { // GIF format, send proper content-type and do not process Header("Content-Type: image/gif"); readfile($filename); exit; } elseif ($image_format==2) { // JPEG format, send proper content-type and process Header("Content-Type: image/jpg"); $old_image=imagecreatefromjpeg($filename); } elseif ($image_format==3) { // PNG format, send proper content-type and process Header("Content-Type: image/png"); $old_image=imagecreatefrompng($filename); } else { // Show error message instead Header("Content-Type: text/plain"); echo "Unknown file format: $_SERVER['PATH_INFO']\n"; exit; }And then of course another problem is it does not send a Last-Modified header that would allow a browser to cache the image. Well you get what you paid for.
Atropos | openvein.org
|
|
|
|
Subject
|
Re: help on watermark php script
[re: Atropos7]
|
| | Posted by | rlparker (DH Smarty Pants) | | Posted on | 07/28/06 06:35 PM |
|
|
One of the reasons I enjoy hanging out here so much is the ability to learn from the "Dreamninjas". Thanks Atropos7! You Rock! Since the script is GNU/GPL, are you gonna submit that back to the author? --rlparker
|
|
|
|
Subject
|
Re: help on watermark php script
[re: kchrist]
|
| | Posted by | rlparker (DH Smarty Pants) | | Posted on | 07/28/06 06:39 PM |
|
|
That is a nice "general purpose" work-around for situations like this one. Thanks for reminding me of that, as I had *completely* forgotten that capability remained. There are *lots* of smart people here! --rlparker
|
|
|
|
Subject
|
Re: help on watermark php script
[re: rlparker]
|
| | Posted by | Atropos7 (DH DreamNinja) | | Posted on | 07/28/06 11:25 PM |
|
|
How about I just write a replacement that will work with DreamHost and PHP 5. I wouldn't feel like submitting a patch for that script because it would be better to re-write it anyway. It might be a good example of watermarking an image but its a bad example of a script in general.
Atropos | openvein.org
|
|
|
|
Subject
|
Re: help on watermark php script
[re: Atropos7]
|
| | Posted by | rlparker (DH Smarty Pants) | | Posted on | 07/29/06 00:00 AM |
|
|
In reply to:
It might be a good example of watermarking an image but its a bad example of a script in general.
Agreed! And I think a re-write would be great. Frankly, *I* don't yet have the skills to do it. I would use the re-write compared to the original as a learning tool to increase my understanding, and I'm sure many Dreamhoster's would appreciate having it work.
I also think that your doing such a re-write would be a generous thing to do. If you have the time, I'd love to see the result!
--rlparker
|
|
|
|
Subject
|
Re: help on watermark php script
[re: Atropos7]
|
| | Posted by | fakestar (DH Dreamling) | | Posted on | 07/29/06 05:06 PM |
|
|
Yes, true, it would be great a re-write! It's a very useful script for people (like me) don't know PHP stuff.
|
|
|
|
Subject
|
Re: help on watermark php script
[re: Atropos7]
|
| | Posted by | silkrooster (DH Smarty Pants) | | Posted on | 07/29/06 08:56 PM |
|
|
I think it would be an excellent idea, I beleive information about using graphics with php is a liuttle lacking anyway. Silk
|
|
|
|
Subject
|
Re: help on watermark php script
[re: silkrooster]
|
| | Posted by | netdcon (DH Regular) | | Posted on | 07/31/06 03:47 PM |
|
|
In reply to:
I think it would be an excellent idea, I beleive information about using graphics with php is a liuttle lacking anyway.
If y'all seem interested in some of these gd lib goodies, I'll slap together a Wiki stub once all my end-of-month nuisance at $DAYJOB has settled in a coupla days. Just simple stuff about how to proportionally resize to thumbnails without having to store a separate thumbnail, how to resize images based on the client's screen resolution, alternate means of protecting images, etc. If anyone thinks it'd be worth the fuss, that is.
Oh, and ps. to fakestar: That bit about RentaCoder was just a gag (..geek humor - go figure..); I sorta got the impression you would've wanted to fix it yourself once I popped the hints. The whole (somewhat quick-n-dirty) fix would've only taken about 2-3 lines of replaced code, creating a new directory for your images with some tight (700) permissions, adding two lines to your .htaccess, then you'd have to go change the <img> tags with the new src= in your HTML or whatever. Wouldn't even make 10 mins work since I've already got the first part coded.
But since the best fix is the easiest and ya already got it working, don't fix what ain't broke 
|
|
|
|
Subject
|
Re: help on watermark php script
[re: rlparker]
|
| | Posted by | Atropos7 (DH DreamNinja) | | Posted on | 08/03/06 02:21 AM |
|
|
Instead of starting from scratch I am mostly cleaning up their code and adding a bit of error handling. Edited the README file as well.
The result (so far) is available at: http://atropos.openvein.org/web/dreamhost/php/watermark/source/
My error handling needs a bit of work still, and I will also need to go through the code and comment what the blocks do.
And again works for me on a subdomain configured to use PHP 5.1.2 instead of 4.4.2
Atropos | openvein.org
|
|
|
|
Subject
|
Re: help on watermark php script
[re: Atropos7]
|
| | Posted by | rlparker (DH Smarty Pants) | | Posted on | 08/03/06 02:31 AM |
|
|
Wow, that was quick! I'll run over an have a look-see. I think it is *great* you are doing this, and I appreciate the chance to learn from you re-written code. Thanks again!
--rlparker
|
|
|
|
Subject
|
Re: help on watermark php script
[re: rlparker]
|
| | Posted by | Raz2133 (DH DreamNinja) | | Posted on | 08/03/06 09:38 PM |
|
|
In reply to:
I think it is *great* you are doing this, and I appreciate the chance to learn from you re-written code.
Me too :)
I am still learning PHP and this script will definitely help my learning process. Well done Atropos.
I might also have a use for the script in a site I am currently doing.
Once again, well done and thanks :)
Mark
-- Save $50 on DreamHost hosting using promo code SAVEMONEY ( Click for promo code details )
|
|
|
|
Subject
|
Re: help on watermark php script
[re: Atropos7]
|
| | Posted by | fakestar (DH Dreamling) | | Posted on | 08/06/06 02:09 AM |
|
|
Yeah, it's working! :)
Example:
http://fotocomedia.com/images/articles/coelho-gigante-assustando-menina_1.jpg
I'm comparing old and new script, i really want to learn php. I think i'm doing well, i'm trying to modify an image gallery script, just to learn, not able to write my own stuff yet...so, thank you very much for spend your time in this watermark script!
|
|
|
|
Subject
|
Re: help on watermark php script
[re: Atropos7]
|
| | Posted by | fakestar (DH Dreamling) | | Posted on | 09/20/06 08:59 PM |
|
|
I noticed the script is decreasing the quality of original Jpeg, if i upload a 60kb jpeg image, after watermarking, the file is like 30kb or less.
How can i control the quality of jpeg output?
Thanks again!
|
|
|
|
Subject
|
Re: help on watermark php script
[re: fakestar]
|
| | Posted by | gordaen (DH Enthusiast) | | Posted on | 09/21/06 09:54 AM |
|
|
The imagejpg() function can accept up to three agruments, the third of which is quality. It should default to ~75. If you don't want to save, use NULL for the second argument.
Check out Gordaen's Knowledge, the blog, and the MR2 page.
|
|
|