Mac*_*Mac 2 php image-manipulation image-processing 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);
?>
Run Code Online (Sandbox Code Playgroud)
它通过访问:
哪个工作正常...但输出很糟糕:
替代文字http://i47.tinypic.com/119s47a.jpg
有人可以修复我的代码为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);
?>
Run Code Online (Sandbox Code Playgroud)
$newwidth = 150;
$newheight = 150;
imagecopyresized($create, $image, 0, 0, 0, 0, $newwidth, $newheight, $oldwidth, $oldheight);
Run Code Online (Sandbox Code Playgroud)