PHP gd Proportional scaling compression picture function _php Skills

Source: Internet
Author: User
Tags chr imagejpeg transparent color learn php learn php programming php programming

This example for you to share the PHP gd proportional scaling compression picture function for your reference, the specific contents are as follows

<?php/** * desription judge whether gif animation * @param sting $image _file Picture Path * @return Boolean t is f/function
    Check_gifcartoon ($image _file) {$fp = fopen ($image _file, ' RB ');
    $image _head = fread ($fp, 1024);
    Fclose ($FP); Return Preg_match ("/") Chr (0x21). chr (0xff). chr (0x0b). ' NETSCAPE2.0 '. '
  /", $image _head)? false:true; /** * desription Compressed picture * @param sting $imgsrc Picture path * @param string $IMGDST Compressed save path/function Compressed_im
    Age ($IMGSRC, $IMGDST) {list ($width, $height, $type) =getimagesize ($IMGSRC);
    $new _width = ($width >600?600: $width) *0.9;
    $new _height = ($height >600?600: $height) *0.9;
        Switch ($type) {Case 1: $giftype =check_gifcartoon ($IMGSRC);
          if ($giftype) {header (' content-type:image/gif ');
          $image _wp=imagecreatetruecolor ($new _width, $new _height);
          $image = Imagecreatefromgif ($IMGSRC);
Imagecopyresampled ($image _wp, $image, 0, 0, 0, 0, $new _width, $new _height, $width, $height);          75 represents the quality, compressed picture capacity size imagejpeg ($image _wp, $IMGDST, 75);
        Imagedestroy ($image _wp);
      } break;
        Case 2:header (' content-type:image/jpeg ');
        $image _wp=imagecreatetruecolor ($new _width, $new _height);
        $image = Imagecreatefromjpeg ($IMGSRC);
        Imagecopyresampled ($image _wp, $image, 0, 0, 0, 0, $new _width, $new _height, $width, $height);
        75 represents the quality, compressed picture capacity size imagejpeg ($image _wp, $IMGDST, 75);
        Imagedestroy ($image _wp);
      Break
        Case 3:header (' content-type:image/png ');
        $image _wp=imagecreatetruecolor ($new _width, $new _height);
        $image = Imagecreatefrompng ($IMGSRC);
        Imagecopyresampled ($image _wp, $image, 0, 0, 0, 0, $new _width, $new _height, $width, $height);
        75 represents the quality, compressed picture capacity size imagejpeg ($image _wp, $IMGDST, 75);
        Imagedestroy ($image _wp);
    Break

 }
  }

PHP and GD function reference table
Gd_info to obtain information about the currently installed GD Library
GetImageSize Get image size
Getimagesizefromstring get the size of an image from a string
Image_type_to_extension gets the file suffix of the image type
Image_type_to_mime_type gets the MIME type of the image type returned by Getimagesize,exif_read_data,exif_thumbnail,exif_imagetype
Image2wbmp output the image to a browser or file in WBMP format
Imageaffine return an image containing the affine tramsformed src image, using a optional clipping area
Imageaffinematrixconcat Concat two matrices (as in doing many ops on one go)
Imageaffinematrixget return an image containing the affine tramsformed src image, using a optional clipping area
Imagealphablending Set Image Blending mode
Imageantialias use anti-aliasing (AntiAlias) features
IMAGEARC Draw an elliptical arc
Imagechar to draw a character horizontally
Imagecharup to draw a character vertically
Imagecolorallocate assign color to an image
Imagecolorallocatealpha assigns color + alpha to an image
Imagecolorat Gets the color index value of a pixel
Imagecolorclosest gets the index value of the color closest to the specified color
Imagecolorclosestalpha gets the closest color to the specified color plus transparency
IMAGECOLORCLOSESTHWB the black and white index of the closest chroma to a given color.
Imagecolordeallocate to remove Image color distribution
Imagecolorexact gets the index value of the specified color
Imagecolorexactalpha gets the index value of the specified color plus transparency
Imagecolormatch makes the color palette version of an image more matched to the true color version
Imagecolorresolve gets the index value of the specified color or the closest possible substitution value
Imagecolorresolvealpha gets the index value of the specified color + alpha or the closest possible substitution value
Imagecolorset set color to the specified palette index
Imagecolorsforindex gets the color of an index
Imagecolorstotal gets the number of colors in the palette of an image
Imagecolortransparent defines a color as a transparent color
Imageconvolution with coefficients div and offset apply for a 3x3 convolution matrix
Part of the imagecopy copy image
Imagecopymerge copy and merge part of image
Imagecopymergegray copy and merge part of image with grayscale
imagecopyresampled resample Copy part image and resize
imagecopyresized copy partial images and resize them
Imagecreate Create a new palette-based image
IMAGECREATEFROMGD2 a new image from a GD2 file or URL
Imagecreatefromgd2part a new image from a given GD2 file or from a section in a URL
IMAGECREATEFROMGD a new image from the GD file or URL
Imagecreatefromgif creates a new image from a file or URL.
Imagecreatefromjpeg creates a new image from a file or URL.
Imagecreatefrompng creates a new image from a file or URL.
Imagecreatefromstring a new image from an image stream in a string
Imagecreatefromwbmp creates a new image from a file or URL.
IMAGECREATEFROMWEBP creates a new image from a file or URL.
IMAGECREATEFROMXBM creates a new image from a file or URL.
IMAGECREATEFROMXPM creates a new image from a file or URL.
Imagecreatetruecolor Create a new true color image
Imagecrop crop an image using the given coordinates and size, x, y, Width and height
Imagecropauto crop an image automatically using one of the available modes
Imagedashedline draw a dotted line
Imagedestroy destroys an image
Imageellipse Draw an Ellipse
Imagefill Area Fill
IMAGEFILLEDARC draw an elliptical arc and fill
Imagefilledellipse Draw an Ellipse and fill
Imagefilledpolygon draw a polygon and fill
Imagefilledrectangle Draw a rectangle and fill
Imagefilltoborder region fills the bounds of the specified color
ImageFilter Use filters on images
Imageflip flips an image using a given mode
Imagefontheight Get font height
Imagefontwidth Get font width
Imageftbbox gives a text box that uses the FreeType 2 font
Imagefttext writes text to an image using FreeType 2 fonts
Gamma correction for GD images using Imagegammacorrect
IMAGEGD2 output GD2 image to browser or file
Imagegd to output GD image to browser or file
Imagegif output image to browser or file.
Imagegrabscreen captures the whole screen
Imagegrabwindow captures a window
Imageinterlace Activate or disable interlaced scanning
Imageistruecolor Check if the image is a true color image
Imagejpeg output image to browser or file.
Imagelayereffect set the alpha process color flag to use the bound libgd layering effect
Imageline Draw a line segment
Imageloadfont Load a new font
Imagepalettecopy copies the palette from one image to another
Imagepalettetotruecolor converts a palette based image to True Color
Imagepng output the image to a browser or file in PNG format
Imagepolygon Draw a polygon
Imagepsbbox gives a text box that uses PostScript Type1 font
Imagepsencodefont change the character encoding vector in the font
Imagepsextendfont Expand or Compact fonts
Imagepsfreefont frees memory occupied by a PostScript Type 1 font
Imagepsloadfont load a PostScript Type 1 font from a file
Imagepsslantfont Tilt A font
Imagepstext the text string on the image with PostScript Type1 font
Imagerectangle Draw a rectangle
Imagerotate to rotate an image with a given angle
Imagesavealpha sets the tag to save the full alpha channel information when the PNG image is saved (as opposed to a single transparent color)
Imagescale Scale an image using the given new width and height
Imagesetbrush set the brush image for drawing lines
Imagesetinterpolation Set the Interpolation method
Imagesetpixel draw a single pixel
Imagesetstyle set the style of drawing lines
Imagesetthickness set the width of the drawing line
Imagesettile set the texture for filling
Imagestring horizontally to draw a line of string
Imagestringup to draw a line vertically
Imagesx Get Image width
Imagesy Get Image Height
Imagetruecolortopalette converts a true color image to a palette image
Imagettfbbox gets the range of text that uses TrueType fonts
Imagettftext writes text to an image with a TrueType font
Imagetypes returns the image types supported by the current PHP version
Imagewbmp output the image to a browser or file in WBMP format
IMAGEWEBP Output an WebP image to browser or file
IMAGEXBM output XBM image to browser or file
iptcembed embeds binary IPTC data into a JPEG image
iptcparse resolves a binary IPTC block to a single tag
Jpeg2wbmp to convert JPEG image files to WBMP image files
Png2wbmp Convert PNG image file to WBMP image file

The above is the entire content of this article, I hope that you learn PHP programming help.

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.