Home > Backend Development > PHP Problem > How to modify the size of uploaded images in php

How to modify the size of uploaded images in php

藏色散人
Release: 2023-03-05 20:26:01
Original
3280 people have browsed it

How to modify the size of the uploaded image in php: first open the script file; then use the getimagesize function to obtain the image size; finally modify the image size through functions such as imagecreatetruecolor.

How to modify the size of uploaded images in php

Recommendation: "PHP Video Tutorial"

How to modify the image size in PHP

Mainly implemented through imagecreatetruecolor.

$filename = "./QR/$id.jpg";
$percent = 0.4;
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p,'./images/thumb/'.$id.'.jpg');
Copy after login

filename is the file name;

percent is the reduction ratio;

imagejpeg is the output saved image.

The above is the detailed content of How to modify the size of uploaded images in php. For more information, please follow other related articles on the PHP Chinese website!

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