Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Basic Image Copying

The two functions imagecopy() and imagecopymerge() are similar in that they copy one picture into another. Both of their first eight parameters are identical:

  • The destination image you're copying to

  • The source image you're copying from

  • The X coordinate you want to copy to

  • The Y coordinate you want to copy to

  • The X coordinate you want to copy from

  • The Y coordinate you want to copy from

  • The width in pixels of the source image you want to copy

  • The height in pixels of the source image you want to copy

Parameters three and four allow you to position the source image where you want it on the destination image, and parameters five, six, seven, and eight allow you to define the rectangular area of the source image that you want to copy. Most of the time, you will want to leave parameters five and six at 0 (copy from the top-left corner of the image), and parameters seven and eight at the width of the source image (the bottom-right corner of it) so that it copies the entire source image.

The way these functions differ is in the last parameter: imagecopy() always overwrites all the pixels in the destination with those of the source, whereas imagecopymerge() merges the destination pixels with the source pixels by the amount specified in the extra parameter: 0 means "Keep the source picture fully," 100 means "Overwrite with the source picture fully," and 50 means "Mix the source and destination pixel colors equally." The imagecopy() function is therefore equivalent to calling imagecopymerge() ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page