Function used to generate a thumbnail when uploading an image

Source: Internet
Author: User

Introduction: This is a detailed page of functions used to generate thumbnail images when uploading images. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 325459 'rolling = 'no'>

Author/Source: keniv

Function used to generate a thumbnail when uploading an image

Practical application see http://feifei2.bjedu.gov.cn/cgi-bin/funnymovie.php

// There are many funny movies

// This function extracts the image from the source file, sets it to the specified size, and outputs it to the target file.

// Source file format: GIF, JPG, and PNG

// Target file format: JPG

// $ Srcfile: source file

// $ Dstfile: target file

// $ Dstw: Target Image Width

// $ DTH: height of the target file

Function makethumb ($ srcfile, $ dstfile, $ dstw, $ dsomething ){

$ DATA = getimagesize ($ srcfile, & $ info );

Switch ($ data [2]) {

Case 1:

$ Im = @ imagecreatefromgif ($ srcfile );

Break;

Case 2:

$ Im = @ imagecreatefromjpeg ($ srcfile );

Break;

Case 3:

$ Im = @ imagecreatefrompng ($ srcfile );

Break;

}

$ Srcw = imagesx ($ IM );

$ Srch = imagesy ($ IM );

$ Ni = imagecreate ($ dstw, $ dsomething );

Imagecopyresized ($ Ni, $ im, 0, 0, 0, $ dstw, $ dsomething, $ srcw, $ srch );

Imagejpeg ($ Ni, $ dstfile );

// If You Need to output data to the browser, change the previous sentence to imagejpeg ($ Ni );

// If you need images in other formats, you can change the last sentence.

More articles about "functions for generating thumbnail images when uploading images"

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/325459.html pageno: 14

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.