php - 动态缩略图 PHP

标签 php image-processing image-manipulation on-the-fly

我想到了这个:

<?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/

相关文章:

php - 在Woocommerce 3中的销售徽章上显示折扣百分比

matlab - 删除图像中的小块标签

c++ - 拉普拉斯滤波器 opencv c++

android - 使用 PorterDuff 模式删除位图部分

php - 运行 Symfony 控制台命令后 Docker php-fpm 容器退出并显示代码 0

php - mysql 如何在某些托管站点上编辑 my.ini

php - 为什么 symfony 中的 post 请求会被识别为 GET

ios - 在 Swift iOS 中使用 OpenCV

image - 使用 Imagemagick,如何裁剪白色背景?

javascript - 使用 Javascript 进行图像处理?