Shoutbox

imagecopy in PHP - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: imagecopy in PHP (/showthread.php?tid=30971)

imagecopy in PHP by Moo on 09-04-2004 at 02:03 PM

I'm a PHP [Image: newbie.gif] and I'd like to know how to use imagecopy (http://is2.php.net/manual/en/function.imagecopy.php). Can you guys help me?

Thanks!


RE: imagecopy in PHP by Choli on 09-04-2004 at 02:18 PM

quote:
int imagecopy ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h)


Copy a part of src_im onto dst_im starting at the x,y coordinates src_x, src_y with a width of src_w and a height of src_h. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y.

imagecopy copies a block (or region, or rectangle) of an image into another one. It takes 8 parameters:

The two first ones are the destination and source images, respectively.

The last four parameters represent the part of the original image that will be copied. They are the coordinates of the upper left pixel of the rectangle (src_x and src_y) and the width and heigh of the rectangle (src_w and src_h).

The other 2 parameters are dst_x and dst_y, and they represent where the rectangle is going to be placed in in the destination image. They're also the upper left pixel.

If you don't understand that, just ask; but in that case I'd suggest you to begin with easier things in PHP ;)
RE: imagecopy in PHP by Moo on 09-04-2004 at 02:30 PM

I dont understand (i was just looking for a way to kinda merge 2 images together one of 'em is an image from a script and the other is a normal image)


RE: imagecopy in PHP by fluffy_lobster on 09-04-2004 at 06:13 PM

ok, i'll go through the arguments for you in order.  each bullet is an argument (one of the parameters separated by commas):

  • dst_im is the image you're placing the other image on top of.  I assume that's the one created by the script, so it will already have a resource variable.  Probably $im.
  • src_im is the same kind of reference to an image as the first one.  If this is a normal image, you first have to load it into an image resource, using imagecreatefrom*(), for example: $im2 = ImageCreateFromGIF('foo.gif');  -- you then use $im2 as the argument in this function
  • dst_x is the number of pixels from the left of the first image that you want the second image to start.  so if you wanted it on the absolute left, this is 0
  • dst_y is the same thing but from the top.  if you want to copy the image to 10px below the top of the image then set this to 10, etc.
  • src_x is the point from the left of the second image that you want to start copying the image.  if you want the whole image this will be 0.  if you want to crop off the first 10 pixels on the left then this is 10.
  • src_y is the same for the vertical dimensions.  a pixel dimension from the top of the second image
  • src_w is the width of the box that will copy from the second image.  if you want to copy on the whole image then this is the image's width.  if you cropped 10px off the left, this will be 10 fewer than that.  gottit?
  • src_h is the same, but for the height

at the end of it, the image linked to by the resource in the first argument will be updated with the copy of image 2 as you specified
RE: imagecopy in PHP by Moo on 09-04-2004 at 06:15 PM

i dont know where to put those arguments (should've said that earlier...)


RE: imagecopy in PHP by fluffy_lobster on 09-04-2004 at 06:17 PM

inside the brackets.

imagecopy(arg1,arg2,...)


RE: imagecopy in PHP by Moo on 09-04-2004 at 06:19 PM

this isnt really for me... too complicated