FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


image on top of image





janszmatt
can i place an image on another image using php?
LukeakaDanish
The first short answer is: Yes.

The second short answer is: search google for how to do it Wink

The third short answer is that in most cases you might aswel use HTML/CSS to do the job.

(the fourth short answer is: i will help you with the HTML/CSS if you want)
janszmatt
yes i would like you to help me

btw can a text box or a drop list be able to do so ?
LukeakaDanish
Yes, anything can be put ontop of something else.

Here are instructions on 2 ways to do this:

(if you use this, and the object goes ontop of something else, it will automatically go over, not under)

Nr 1: Absolute Positioning


This is the easiest method to understand. Basically, absolute positioning lets you place an object precisely where you want it.

Inside your element (<img>,<div>,<select>,etc...) place the following code:

Code:
style="position: absolute; top: 50px; left: 50px;"


The two 50px's need to be changed to #px where # is the amount of pixels you want the object to be away from the left/top edge of the screen (viewport)*


Nr 1: Relative Positioning


This is slightly more difficult to understand, however much better for many purposes:

Inside your element (<img>,<div>,<select>,etc...) place the following code:

Code:
style="position: relative; top: 50px; left: 50px;"


The two 50px's need to be changed to #px where # is the amount of pixels you want the object to be "nudged" away from its current position - just do some testing to fid out how it works.


* = if you add an element which is positioned absolutely or relatively around your absolutely positioned object, it will calculate its position using the edge of the surrounding object instead of the screen (viewport)




Hope this helped...
Philip
err.. i think u need to set the tag like this <div style="position:absolute;z-index:9999" ><img src="xxxx"></div>

z-index: <- the more higher value then it will in the most top. Wink
bladesage
janszmatt wrote:
can i place an image on another image using php?


Okay, once you've created an image resource in your PHP script, you need to have another image resource to copy it from. You can create the second image resource using imagecreate(width, height) (for an image from scratch), imagecreatefrompng(filename) (for a .png image file), imagecreatefromgif(filename) (for a .gif image file), imagecreatefromjpeg(filename) (for a .jpg or .jpeg file), or imagecreatefromwbmp(filename) (for a .wbmp file).

Then, you can use imagecopy() to copy image 2 onto image 1. Here is an example.
Code:
$img1 = imagecreate(900, 600);
$img2 = imagecreatefrompng('images/image2.png');
imagecopy($img1, $img2, 4, 5, 0, 0, imagesx($img2), imagesy($img2));

imagepng($img1);


This example would create an image with the size 900x600, and copy the file images/image2.png onto the new image. It tells it to copy it to the coordinates 4, 5; and find the image's width and height automatically (using imagesx() and imagesy()).

Hope this clears things up for you Very Happy.

Philip wrote:
err.. i think u need to set the tag like this <div style="position:absolute;z-index:9999" ><img src="xxxx"></div>

z-index: <- the more higher value then it will in the most top. Wink


The z-index property goes from front to back, meaning that it specifies depth. Higher depth means it will be back farther.

And as he is asking about PHP and not (X)HTML or CSS, I believe he is asking about actual PHP functions, not HTML or CSS stylings. Either that, or he's in the wrong forum.
LukeakaDanish
bladesage wrote:
...
And as he is asking about PHP and not (X)HTML or CSS, I believe he is asking about actual PHP functions, not HTML or CSS stylings. Either that, or he's in the wrong forum.


@Bladesage:

If you read my first post, and his second it would appear (I certainly think so) that he doesn't really know whether he wants php or html/css.

Helping him the html/css way surely isnt a problem, even though this is the php forum?
Related topics
PHP Tutorials
Header image change? How to!!
Whats Your Top 10 Desktop Applications
How about a special top poster rank?
Image Mapping?
Jamatus' Dynamic image store
phpbb2 top corner icon
css placements of image links(the best way to do it)
secure your pictures on a web page !
image upload, and return url to image
How to make a image view from bluring to sharp ?
PHP Image Questions
positioning div top right
random pics XD
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.