Php image scaling implementation _ PHP Tutorial

Source: Internet
Author: User
Php image scaling implementation method. Php basic exercise-image scaling: Copy the code as follows :? Php *** imagezoom. * functionimageZoom ($ filename, $ w, $ h) {* Argumentsmeaning ** $ filename: thesourceofth php basic exercise-image scaling:

The code is as follows:


/**
* Image zoom.
*/
Function imageZoom ($ filename, $ w, $ h ){
/* Arguments meaning */
/* $ Filename: the source of the name */
/* $ W: you want get the image's width */
/* $ H: you want get the imgage's height */
$ Arr = getimagesize ($ filename );
$ Src_w = $ arr [0];
$ Src_h = $ arr [1];
$ Src_t = $ arr [2];
/* 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF (intel byte order ),
= TIFF (motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC,
= IFF, 15 = WBMP, 16 = XBM */
$ Src_m = $ arr ['Mime '];

$ Src_img = imagecreatefromjpeg ($ filename );

If ($ w/$ src_w)> ($ h/$ src_h )){
$ Bili = $ h/$ src_h;
} Else {
$ Bili = $ w/$ src_h;
}
$ Dst_w = $ src_w * $ bili;
$ Dst_h = $ src_h * $ bili;
$ Dst_img = imagecreatetruecolor ($ dst_w, $ dst_h );

Imagecopyresampled ($ dst_img, $ src_img, 0, 0, 0, $ dst_w, $ dst_h, $ src_w, $ src_h );

Header ("content-type: {$ src_m }");

Switch ($ src_t ){
Case 1:
$ Imgout = "imagegif ";
Break;
Case 2:
$ Imgout = "imagejpeg ";
Break;
Case 3:
$ Imgout = "imagepng ";
Break;
Default:
Echo "The type was wrong! ";
Break;
}

$ Dst_filename = "s _". $ filename;
$ Imgout ($ dst_img, $ dst_filename );

Imagedestroy ($ dst_img );
}
$ Filename = 'gg.jpg ';
ImageZoom ($ filename, 100,200 );

Core: <1> pay attention to how the zoom ratio is obtained. although the image may be slightly different from the expected one, the zoom ratio is guaranteed at least.

<2> type control.

The pipeline code is as follows :? Php/*** image zoom. */function imageZoom ($ filename, $ w, $ h) {/* Arguments meaning * // * $ filename: the source of th...

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.