PHP image Processing

Source: Internet
Author: User

PHP image processing get picture resources

Resource Imagecreatefromxxxx (String $filename)
Returns an image identifier that represents an image obtained from a given file name. get picture Related information

GetImageSize ()

The function will determine the size of any GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM or WBMP image file and return the size of the image as well as the file type and an IMG that can be used in normal HTML files The Height/width text string in the tag.

Array (7) {
  [0] =>
  int (
  1] =>
  int ()
  [2] =>
  int (2)
  [3] =>
  string (22 "Width=" height= "'
  bits ' =>
  int (8)
  ' channels ' =>
  int (3)
  ' MIME ' =>
  String "Image/jpeg"
}

returns an array of four cells.
index 0 contains the pixel value of the image width, and
index 1 contains the pixel value of the image height.
index 2 is the tag of the image type: 1 = gif,2 = jpg,3 = png,4 = swf,5 = psd,6 = bmp,7 = TIFF (Intel byte order), 8 = TIFF (Motorola byte Orde r), 9 = jpc,10 = jp2,11 = jpx,12 = jb2,13 = swc,14 = iff,15 = wbmp,16 = XBM. These tags correspond to the newly added imagetype constants of PHP 4.3.0.
Index 3 is a text string with the contents "height=" yyy "width=" xxx, which can be used directly for the IMG tag.
read the RGB of a point

int Imagecolorat (Resource image,int image, int x, int $y)
Returns the color index value of the pixel at the specified position in the shape specified by image.
If PHP compiles with a version of GD Library 2.0 or higher and the image is a true color image, this function returns the RGB value of the point as an integer. Use the shift mask to get the values of the red, green, and blue components:

Array Imagecolorsforindex (resource image,int image, int index)
This function returns an associative array of key names with Red,green,blue and alpha that contains the corresponding values for the specified color index.

$im = Imagecreatefrombmp ($fileName);
$rgb = Imagecolorat ($im, MB);

$r = ($rgb >>) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

or 

Imagecolorsforindex ($im, $RGB);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.