KermM, I know you have some experience here with these Cemetech User Sig tags but what are the limitations of this function? Can it work with JPEGS?

All I really want to do is take a watermark image from a location on my server and a photograph from another folder then layer the two for website display. If I could adjust the size (both watermark and image), that'd also be great too!
comicIDIOT wrote:
KermM, I know you have some experience here with these Cemetech User Sig tags but what are the limitations of this function? Can it work with JPEGS?

All I really want to do is take a watermark image from a location on my server and a photograph from another folder then layer the two for website display. If I could adjust the size (both watermark and image), that'd also be great too!
Yup, this is very easily done, and I'd be happy to assist you. How about a function that takes a relative path to the image, a relative path to the watermark, and the size and location of the watermark? Do you want it to directly output the jpeg data to the browser, or store it somewhere? I think a good place to start would be a function prototype.
Storing it somewhere would be great. I don't update my portfolios enough to render every time the page loads, and I have a bandwidth limit.

I'm all for a function prototype; I'll place it on my beta sub-domain. I'm taking it I can find basic documentation on PHP.net?
comicIDIOT wrote:
Storing it somewhere would be great. I don't update my portfolios enough to render every time the page loads, and I have a bandwidth limit.

I'm all for a function prototype; I'll place it on my beta sub-domain. I'm taking it I can find basic documentation on PHP.net?
Err, sorry, I think my terminology confused you. Smile This is a function prototype, for example:


Code:
function myfunction(arg1, arg2, arg3) {}
//arg1 - integer, contains blah
//arg2 - string, describes foo
//arg3 - array, contains all bar
//returns blahfoobarbarbar


It's just the first line of the function without the body of the function, describing what the function takes as arguments and what it returns. This is an example of a function prototype for the C main function:


Code:
int main(int argc, char* argv[]);


Or the same, in Java:


Code:
public static void main(String[] args)
Got it! Rolling Eyes

Code:
function watermark(image, water, size, out) {}
//image - Image to be resized and watermarked.
//water - watermark location
//size - size in pixels for longest side of image, watermark will be percentage of this.
//out - Where the image will be saved to.
[/code]
How about passing a pctsize for the watermark relative to the image instead? Smile I'm thinking something like this.

Standard disclaimer: Haven't tried it yet, just wrote this off-the-cuff. I checked that I'm using the right syntax and args for the image*() functions, though.


Code:
function watermark($image, $water, $pctsize, $out) {
    if (FALSE === ($im_im = imagecreatefromjpeg($image)))
        return -1;
    if (FALSE === ($im_wm = imagecreatefromjpeg($water)))
        return -2;
    $im_width = imagesx($im_im);
    $im_height = imagesy($im_im);
    $wm_width = imagesx($im_wm);
    $wm_height = imagesy($im_ym);
    if (($wm_width/$im_width) > ($wm_height/$im_height)) {
        $wm_pct = $pctsize*($im_width/$wm_width);
    } else {
        $wm_pct = $pctsize*($im_height/$wm_height);
    }
    $wm_x = floor(($im_width - ($wm_pct*$wm_width))/2);
    $wm_y = floor(($im_height - ($wm_pct*$wm_height))/2);
    imagecopyresized($im_im,$im_wm,$wm_x,$wm_y,0,0,floor($wm_pct*$wm_width),floor($wm_pct*wm_height),$wm_width,$wm_height);
    imagejpeg($im_im,$out);
    return 0;
}
Alright, I'll try it out when I open my FTP back up P:

Thanks!
comicIDIOT wrote:
Alright, I'll try it out when I open my FTP back up P:

Thanks!
To be honest, I don't have the highest hopes that it will work directly out of the box, but I'll be happy to work with you to solve any issues you turn up. A basic outline of functionality is that it first tries to open the source and watermark images, and returns a negative number if either fails. Then, it finds what size the watermark should be and overlays it, centered, on the source image. Since you're probably going to want it to be semitransparent, we'll have to change that command to properly add transparency. It then saves the result and returns 0.
Centred wouldn't be a good idea as this is going to be on my portfolio :(

And the copyright won't be as big as I have rendered up for client/facebook/elsewhere viewing.


I'm still playing with watermarks and locations, so we'll see what I end up. Perhaps a watermark that suits both! I actually liked this at first but still don't like how much it white-outs the image below.
OK, sounds good. We can easily adjust the position-finding code to simply offset the watermark from a corner instead of centering it. Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement