Page 1 of 1
Merging images...
Posted: Fri Dec 10, 2004 3:50 pm
by Todd_Z
What is the bare minimal coding that I can use to merge two images together? I'd rather not use some extensive package to do this - Basically I want to have a function that looks like this:
Code: Select all
<?php
function mergeImages ( $img1, $img2, $x, $y ) {
$newImage = ????;
---
return $newImage;
}
?>
Where $x and $y are the locations for the second image to be placed on $img1.
Posted: Fri Dec 10, 2004 11:58 pm
by idotcom
I would recommend using GD functions. Its easy and you can create one simple and fairly small php function to process the task.
Posted: Sat Dec 11, 2004 3:02 pm
by Todd_Z
Ok... so now I know how to merge images... but what happens if someone right clicks and presses view image... it won't still be watermarked... a fix?
Posted: Sat Dec 11, 2004 3:18 pm
by rehfeld
gd modifies the image. right clicking wont change the image you sent to them
Posted: Sat Dec 11, 2004 3:36 pm
by Todd_Z
I see... how do i do a chdir with a space in the filename? (related issue)
Posted: Sat Dec 11, 2004 3:46 pm
by rehfeld
Todd_Z wrote:I see... how do i do a chdir with a space in the filename? (related issue)
have you tried?
Posted: Sat Dec 11, 2004 4:03 pm
by Todd_Z
Whoops - I was using %20 for spaces by accident... didn't catch that til just now - thanks
Posted: Sat Dec 11, 2004 4:16 pm
by Todd_Z
Alright... Now the implementation of merging images and the whole javascript thing...
http://www.acdrifter.com/Foo/?page=Revi ... e=Returner
So i have that page, and there is a javascript gallery... I need to put a watermark on each one of those images... but the thing is that they are loaded through javascript... The current one and the two in front and in back of it... so anyways... how do i do this? Thanks in advance
Posted: Sat Dec 11, 2004 4:40 pm
by rehfeld
watermark the images, save them, then load them
Posted: Sat Dec 11, 2004 11:03 pm
by Todd_Z
Can i do that on the fly? or should i make a script that goes through each image and watermarks each for me to be used later?
Posted: Sat Dec 11, 2004 11:16 pm
by rehfeld
your choice, whatever works best for your situation
to do it on the fly you would do something like this
<img src="watermarker.php?image=foo.jpg">
then
Code: Select all
$image = $_GETї'image'];
$type = end(explode('.', $image)); // get file ext.
header('Content-type: image/'.$type); // send proper mime header
// then load $image into gd, watermark it, and output it directly to the browser
Posted: Sun Dec 12, 2004 1:41 pm
by Todd_Z
Ahhh thank you rehfeld.
Posted: Mon Dec 13, 2004 11:12 am
by idotcom
I just wanted to post this just incase...
The way I use GD is by creating a simple php file that has all the gd code and in my case, grabs the image from the database with the row ID. This can also be used if the images are stored in folders.
So... I simply feed the php file the id in the image src=""
like: src="myimage.php?image_id=12343&watermark=no&size=1"
if the image comes from a database use image(row) id and if its in a folder use the path:
http://www.domain.com/myimages/image_name.jpg
like: src="myimage.php?image_source=
http://www.domain.com/myimages/image_na ... =no&size=1"
in my php file:
if(image_id)
{
grab the image
}
if(watermark=="no")
{
dont watermark
}
else
{
yes watermark
}
if(size==1)
{
make the image this preset size
}
if(size==2)
{
make the image this size instead
}
doing this seems to give me a lot of freedom. set as many conditions you want and just tell php what to do with the current image in the image path.
Hope this helps.