php 修改图片分辨率
生活随笔
收集整理的這篇文章主要介紹了
php 修改图片分辨率
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<?php
function resize_image($file, $w, $h, $crop=FALSE) {
list($width, $height) = getimagesize($file);
$r = $width / $height;
if ($crop) {
if ($width > $height) {
$width = ceil($width-($width*abs($r-$w/$h)));
} else {
$height = ceil($height-($height*abs($r-$w/$h)));
}
$newwidth = $w;
$newheight = $h;
} else {
if ($w/$h > $r) {
$newwidth = $h*$r;
$newheight = $h;
} else {
$newheight = $w/$r;
$newwidth = $w;
}
}
$src = imagecreatefromjpeg($file);
$dst = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return $dst;
}
$image = resize_image('./go.jpeg', 256, 256);
//imagepng($image, './logo/icon-128x128.png');
imagepng($image, './logo/icon-256x256.png');
var_dump($image);
總結
以上是生活随笔為你收集整理的php 修改图片分辨率的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎样在数组末尾添加数据_如何利用C++实
- 下一篇: FATFS 初学之 f_mount