gpt4 book ai didi

php - 动态缩略图 PHP

转载 作者:行者123 更新时间:2023-12-02 07:13:54 25 4
gpt4 key购买 nike

我想到了这个:

<?php 

$dir = $_GET['dir'];

header('Content-type: image/jpeg');

$create = imagecreatetruecolor(150, 150);
$img = imagecreatefromjpeg($dir);
imagecopyresampled($create, $img, 0, 0, 0, 0, 150, 150, 150, 150);

imagejpeg($create, null, 100);

?>

它通过访问来工作:

http://example.com/image.php?dir=thisistheimage.jpg

哪个工作正常......但输出很糟糕:

alt text

有人可以将我的图像代码修改为 150 x 150 覆盖黑色区域...

谢谢。

解决方案:

<?php 

$dir = $_GET['dir'];

header('Content-type: image/jpeg');

list($width, $height) = getimagesize($dir);

$create = imagecreatetruecolor(150, 150);
$img = imagecreatefromjpeg($dir);

$newwidth = 150;
$newheight = 150;

imagecopyresized($create, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

imagejpeg($create, null, 100);

?>

最佳答案

使用imagecopyresized :

$newwidth = 150;
$newheight = 150;
imagecopyresized($create, $image, 0, 0, 0, 0, $newwidth, $newheight, $oldwidth, $oldheight);

关于php - 动态缩略图 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2940080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com