将 ImageMagick 代码转换为 GD (php)
我想转换一些使用 ImageMagick 进行图像处理的 PHP 代码。在使用 GD 方面我是一个新手,但我希望我能得到一些指导或代码建议。
当前的 PHP 代码如下所示,
$rand = rand();
$galleryWidth ='245';
$galleryHeight ='245';
$result = array();
if (isset($_FILES['photoupload']) )
{
$file = $_FILES['photoupload']['tmp_name'];
$error = false;
$size = false;
list($file_name, $file_type) = split('[.]', $_FILES["photoupload"]["name"]);
move_uploaded_file($_FILES["photoupload"]["tmp_name"],
"./photos/org/".$rand.'.'.$file_type);
list($width,$height)=getimagesize('./photos/org/'. $rand.'.'.$file_type);
if(($galleryWidth/$width) < ($galleryHeight/$height)){
exec("C:/imagemagick/convert ./photos/org/". $rand.".".$file_type."\
-thumbnail ".round(($width*($galleryWidth/$width)), 0)."x".round(($height*($galleryWidth/$width)), 0)." \
-quality 90 ./photos/".$_GET['id'].".jpg");
}
else{
exec("C:/imagemagick/convert ./photos/org/". $rand.".".$file_type."\
-thumbnail ".round(($width*($galleryHeight/$height)), 0)."x".round(($height*($galleryHeight/$height)), 0)." \
-quality 90 ./photos/".$_GET['id'].".jpg");
}
$result['result'] = 'success';
$result['size'] = "Uploaded an image ({$size['mime']}) with {$size[0]}px/{$size[1]}px.";
}
?>
感谢您的查看!
I'd like to convert some PHP code that uses ImageMagick for image processing. I am a total newbie when it comes to using GD but I hope I could get some directions or code suggestions.
The current PHP code can be seen below
$rand = rand();
$galleryWidth ='245';
$galleryHeight ='245';
$result = array();
if (isset($_FILES['photoupload']) )
{
$file = $_FILES['photoupload']['tmp_name'];
$error = false;
$size = false;
list($file_name, $file_type) = split('[.]', $_FILES["photoupload"]["name"]);
move_uploaded_file($_FILES["photoupload"]["tmp_name"],
"./photos/org/".$rand.'.'.$file_type);
list($width,$height)=getimagesize('./photos/org/'. $rand.'.'.$file_type);
if(($galleryWidth/$width) < ($galleryHeight/$height)){
exec("C:/imagemagick/convert ./photos/org/". $rand.".".$file_type."\
-thumbnail ".round(($width*($galleryWidth/$width)), 0)."x".round(($height*($galleryWidth/$width)), 0)." \
-quality 90 ./photos/".$_GET['id'].".jpg");
}
else{
exec("C:/imagemagick/convert ./photos/org/". $rand.".".$file_type."\
-thumbnail ".round(($width*($galleryHeight/$height)), 0)."x".round(($height*($galleryHeight/$height)), 0)." \
-quality 90 ./photos/".$_GET['id'].".jpg");
}
$result['result'] = 'success';
$result['size'] = "Uploaded an image ({$size['mime']}) with {$size[0]}px/{$size[1]}px.";
}
?>
Thanks for having a look at it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会发现 GD 文件格式支持与 ImageMagick 相比有点有限,但您正在寻找类似于以下内容的文件格式。
You'll find GDs file format support is a bit limited compared to ImageMagick's, but you're looking for something similar to the following.