PHP gd proportional Scaling compressed picture function, _php tutorial

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

PHP gd and other proportional scaling compressed picture functions,


The example of this article for you to share the PHP gd and other proportional scaling compressed picture functions for your reference, the specific content as follows

<?php/** * desription determine if GIF animation * @param sting $image _file Picture Path * @return Boolean t is f no */function Check_g    Ifcartoon ($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 save path after compression */function Compressed_image ($im    GSRC, $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 for 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 mass, 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 mass, compressed picture capacity size imagejpeg ($image _wp, $IMGDST, 75);        Imagedestroy ($image _wp);    Break }  }

PHP and GD function reference table
Gd_info obtaining information for the currently installed GD Library
GetImageSize Get image size
Getimagesizefromstring Get the size of an image from a string
Image_type_to_extension get 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 exporting an 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-matrices (as in doing many ops in one go)
Imageaffinematrixget Return An image containing the affine tramsformed src image, using a optional clipping area
Imagealphablending to set the color blending mode of the image
Imageantialias whether to use anti-aliasing (antialias) function
Imagearc Drawing Elliptical Arc
Imagechar to draw a character horizontally
Imagecharup to draw a character vertically
Imagecolorallocate assigning colors to an image
Imagecolorallocatealpha assigning 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 color that is closest to the specified color and transparency
IMAGECOLORCLOSESTHWB Gets the black-white index with the nearest chroma of the given color
Imagecolordeallocate canceling the assignment of image colors
Imagecolorexact gets the index value of the specified color
Imagecolorexactalpha the index value that gets the specified color plus transparency
Imagecolormatch the color of the palette version in an image to match the true color version
Imagecolorresolve gets the index value of the specified color or the nearest alternative value that is likely to be obtained
Imagecolorresolvealpha gets the index value of the specified color + alpha or the nearest alternative value that may be obtained
Imagecolorset set color for the specified palette index
Imagecolorsforindex get the color of an index
Imagecolorstotal gets the number of colors in the palette of an image
Imagecolortransparent to define a color as a transparent color
Imageconvolution applying a 3x3 convolution matrix with the coefficients div and offset
Imagecopy part of a copy image
Imagecopymerge copy and merge part of an image
Imagecopymergegray copy and merge part of an image with grayscale
imagecopyresampled resampling and resizing copies of portions of images
Imagecopyresized copy part of the image and resize it
Imagecreate Creating a new palette-based image
Imagecreatefromgd2 creating a new image from a GD2 file or URL
Imagecreatefromgd2part Create a new image from a given GD2 file or part of a URL
IMAGECREATEFROMGD creating a new image from a 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 creating 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 dashed line
Imagedestroy destroying 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 it
Imagefilledrectangle Draw a rectangle and fill
Imagefilltoborder area fills the bounds of the specified color
ImageFilter using 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 writing text to an image using FreeType 2 font
Imagegammacorrect application of gamma correction to GD image
IMAGEGD2 output the GD2 image to a browser or file
IMAGEGD exporting GD images to a 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 Setting the alpha color-blending flag to use the bound libgd layering effect
Imageline Drawing a line segment
Imageloadfont Loading a new font
Imagepalettecopy copy a palette from one image to another
Imagepalettetotruecolor converts a palette based image to True Color
Imagepng exporting images to a browser or file in PNG format
Imagepolygon Draw a polygon
Imagepsbbox gives a text box with a PostScript Type1 font
Imagepsencodefont changing the character encoding vector in a font
Imagepsextendfont expanding or streamlining fonts
Imagepsfreefont releases the memory occupied by a PostScript Type 1 font
Imagepsloadfont loading a PostScript type 1 font from a file
Imagepsslantfont Tilt A font
Imagepstext a text string on an image with a PostScript Type1 font
Imagerectangle Draw a rectangle
Imagerotate rotating an image with a given angle
Imagesavealpha setting tags to save full alpha channel information when you save a PNG image (as opposed to a single transparent color)
Imagescale scale an image using the given new width and height
Imagesetbrush setting a brush image for drawing lines
Imagesetinterpolation Set the Interpolation method
Imagesetpixel draw a single pixel
Imagesetstyle setting the style of line drawing
Imagesetthickness set the width of the drawing line
Imagesettile setting the map for filling
Imagestring to draw a line of string horizontally
Imagestringup to draw a line of string vertically
Imagesx Get Image width
Imagesy Get Image Height
Imagetruecolortopalette Converting a true-color image to a palette image
Imagettfbbox gets the range of text that uses TrueType fonts
Imagettftext writing text to an image with TrueType fonts
Imagetypes returns the type of image supported by the current PHP version
Imagewbmp exporting an image to a browser or file in WBMP format
IMAGEWEBP Output an WebP image to browser or file
IMAGEXBM output the XBM image to a browser or file
Iptcembed embed binary IPTC data into a JPEG image
Iptcparse to parse binary IPTC blocks into a single tag
Jpeg2wbmp converting a JPEG image file to a WBMP image file
Png2wbmp converting a PNG image file to a WBMP image file

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

http://www.bkjia.com/PHPjc/1136663.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136663.html techarticle PHP gd and other proportional scaling compressed picture function, this example for everyone to share the PHP gd and other proportional scaling compressed picture functions for your reference, specific content as follows PHP/** * desription judgment is ...

  • Related Article

    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.