Example of PHP to upload a file with a natural thumbnail and text

Source: Internet
Author: User
? // Actively scale down the original file $ srcFile, large image; $ photo_small target file, small image; $ dstW, $ dsomething is the width and height of the small image. Functionmakethumb ($ srcFile, $ photo_small, $ dstW, $ dsomething) {$ data = GetImageSize ($ srcFile); switch ($

// Actively scale down the original file $ srcFile, large image; $ photo_small target file, small image; $ dstW, $ dsomething is the width and height of the small image.
Function makethumb ($ srcFile, $ photo_small, $ dstW, $ dsomething ){
$ Data = GetImageSize ($ srcFile );
Switch ($ data [2]) {
Case 1: // image type. 1 is a GIF image.
$ Im = @ ImageCreateFromGIF ($ srcFile );
Break;
Case 2: // image type; 2: JPG
$ Im = @ imagecreatefromjpeg ($ srcFile );
Break;
Case 3: // the image type. 3 is a PNG image.
$ Im = @ ImageCreateFromPNG ($ srcFile );
Break;
}
$ SrcW = ImageSX ($ im); // The width of the original image. you can also apply $ data [0].
$ SrcH = ImageSY ($ im); // The height of the original image. you can also apply $ data [1].
$ SrcX = 0; // coordinates of the Origin chart x, y
$ SrcY = 0;
If ($ srcW/$ dstW)> ($ srcH/$ dsomething) {// Obtain the length and width of a natural image
$ DstW2 = $ dstW; // width and height of the output image
$ DstH2 = $ srcH * $ dstW/$ srcW;
$ DstX = 0; // coordinates of the output image x, y
$ DstY = ($ dsomething-$ dstH2)/2;
}
Else {
$ DstH2 = $ dsomething; // width and height of the output image
$ DstW2 = $ srcW * $ dstW/$ srcH;
$ DstX = ($ dstW-$ dstW2)/2; // output coordinate x, y
$ DstY = 0;
}
$ Ni = imagecreatetruecolor ($ dstW, $ dsomething); // ImageCreate ($ dstW, $ dsomething); draw the size of the blank cloth
$ ColorBody = imagecolorallocate ($ ni, 235,234,233); // defines the background color.
Imagefill ($ ni, $ colorBody); // fill the background color
ImageCopyResized ($ ni, $ im, $ dstX, $ dstY, $ srcX, $ srcY, $ dstW2, $ dstH2, $ srcW, $ srcH );
ImageJpeg ($ ni, $ photo_small );
// ImageJpeg ($ ni); // used to display an image. you can cancel the annotation and display the image directly on the page.
}
// Images with inherent copyright information
Function makeCopyright ($ srcFile, $ dstFile, $ dstW, $ dsomething ){
$ Data = GetImageSize ($ srcFile );
Switch ($ data [2]) {
Case 1: // image type. 1 is a GIF image.
$ SrcImg = @ ImageCreateFromGIF ($ srcFile );
Break;
Case 2: // image type; 2: JPG
$ SrcImg = @ imagecreatefromjpeg ($ srcFile );
Break;
Case 3: // the image type. 3 is a PNG image.
$ SrcImg = @ ImageCreateFromPNG ($ srcFile );
Break;
}
$ SrcW = ImageSX ($ srcImg); // The width of the original image. you can also apply $ data [0].
$ SrcH = ImageSY ($ srcImg); // The height of the original image. you can also apply $ data [1].
 
If ($ srcW/$ dstW)> ($ srcH/$ dsomething) {// Obtain the length and width of a natural image
$ DstW2 = $ dstW; // width and height of the output image
$ DstH2 = $ srcH * $ dstW/$ srcW;
}
Else {
$ DstH2 = $ dsomething; // width and height of the output image
$ DstW2 = $ srcW * $ dstW/$ srcH;
}
$ Dstimg = imagecreatetruecolor ($ dstW2, $ dstH2); // draw the size of the blank flower cloth
ImageCopyResized ($ dstimg, $ srcImg, 0, 0, 0, $ dstW2, $ dstH2, $ srcW, $ srcH );
// Define the text to be written
$ Word = 'http: // www.webjx.com '; // text
$ Font = 5; // font
$ WordColor = imagecolorallocate ($ dstimg, 0x08,0x00,0x00); // color
$ WordX = $ dstW2-200; // x coordinate

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.