PHP creates thumbnails Based on Images

Source: Internet
Author: User
The method for creating thumbnails in php is also very simple. It is to use imagecopyresampled to create a smaller image based on the source image. Let's look at the code check_image_addthumbs.php? Php changes image effects $ dbmysql_connect (localhost, root, Ctrip07185419) ordie (cannotconnecttodatabase)

The method for creating thumbnails in php is also very simple. It is to use imagecopyresampled to create a smaller image based on the source image. Let's look at the code check_image_addthumbs.php? Php // modify image effects $ db = mysql_connect ('localhost', 'root', 'ctrip07185419 ') or die ('can not connect to database ')

The method for creating thumbnails in php is also very simple. You can use imagecopyresampled to create a smaller image based on the source image. Let's look at the code check_image_addthumbs.php.

                         Here is your pic!                Your image has been saved! $ _ POST ['id'];?>. Jpg "alt =" "/>    
                         Here is your pic!                So how does it feel to be famous?

Here is the picture you just uploaded to your servers:

$ Imagename;?> "Style =" float: left; "alt =" "/>
Image save:
Height:
Widht:
Upload date:

You may apply a special effect to your image from the list of option below. Note: saving an image with any of the filters appliedCan be undone

The thumbnail is placed under the path D: \ Serious \ phpdev \ test \ images \ thumbs. Here we add a gallery. php file to display all the thumbnails. The Code is as follows:

             Welcome to our Photo Gallery                        

Click on any image to see it full sized.

' : ' '; $odd = !$odd; extract($row); echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; } ?>
Image Caption Uploaded By Date uploaded
$dir . '/' . $image_id.'.jpg">'; echo '$thumbdir . '/' . $image_id . '.jpg" alt="" />'; echo ''.$image_caption.''.$image_username.''.$image_date.'

To see the effect of the thumbnail:

Note the following code:

$ Thumb_width = $ width * 0.10; $ thumb_height = $ height * 0.10; // create a thumbnail $ thumb = imagecreatetruecolor ($ thumb_width, $ thumb_height); imagecopyresampled ($ thumb, $ image, 0, 0, 0, 0, $ thumb_width, $ thumb_height, $ width, $ height); // Save the original image imagejpeg ($ image, $ dir. '/'. $ _ POST ['id']. '.jpg ', 100); // Save the thumbnail imagejpeg ($ thumb, $ thumbdir. '/'. $ _ POST ['id']. '.jpg ', 100); imagedestroy ($ thumb );

We set the thumbnail length to 10% of the original length, and the width to 10% of the original width. Make sure that the width is the same. Otherwise, the image will be distorted. Of course, if this parameter is set to an integer greater than 1, the image is enlarged.

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.