How to implement the scaling _php technique of PHP picture

Source: Internet
Author: User

Through the article gives the source code can achieve for the picture and so on shrink released into a thumbnail function, very practical skills oh.

New file index.php, you need to have a picture under the statistics directory for pic.jpg (can change the name of the picture according to the source)

The source code is as follows:

<?php
$filename = "pic.jpg";
$per =0.3;
List ($width, $height) =getimagesize ($filename);
$n _w= $width * $per;
$n _h= $height * $per;
$new =imagecreatetruecolor ($n _w, $n _h);
$img =imagecreatefromjpeg ($filename);
Copy part of the image and adjust the
imagecopyresized ($new, $img, 0, 0,0, 0, $n _w, $n _h, $width, $height);
Image output new picture, Save as
imagejpeg ($new, "pic1.jpg");
Imagedestroy ($new);
Imagedestroy ($img);
? >

After using the browser to run, there will be a pic1.jpg in the index.php of the same level, the picture is proportional scaling, the path can be changed in the source code, put in their own projects to go or write a method is also OK.

The above is the entire content of this article, I hope to help you learn.

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.