Home > Backend Development > PHP Tutorial > How to achieve equal scaling of php images_php tips

How to achieve equal scaling of php images_php tips

WBOY
Release: 2016-05-16 20:10:01
Original
1207 people have browsed it

The source code given in the article can realize the function of generating thumbnails according to the proportional scaling of pictures. It is a very practical technique.

Create a new file index.php. You need to have a picture in the statistics directory as pic.jpg (the name of the picture can be changed according to the source code)

The source code is as follows:

<&#63;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部分图像并调整
imagecopyresized($new, $img,0, 0,0, 0,$n_w, $n_h, $width, $height);
//图像输出新图片、另存为
imagejpeg($new, "pic1.jpg");
imagedestroy($new);
imagedestroy($img);
&#63;>
Copy after login

After running it with a browser, there will be pic1.jpg in the directory at the same level as index.php. This image is a scaled image. The path can be changed in the source code and placed in your own project. You can go or write a method.

The above is the entire content of this article, I hope it will be helpful to everyone’s study.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template