作者:可爱的伊比2324767445hMkK | 来源:互联网 | 2017-05-13 02:18
使用ImageMagick,您可以轻松,更快地创建缩略图,比使用PHP的容易得多。
<&#63;php
// Location to upload main image:
$mainDir = $_SERVER['DOCUMENT_ROOT'].'/images/l/';
// Location to create the thumb image:
$smalDir = $_SERVER['DOCUMENT_ROOT'].'/images/s/';
// Command to use:
$command = '/usr/bin/convert';
// Thumbnail width:
$size = 210;
// Make sure we have an image:
if(isset($_POST['submit'])){
if(getimagesize($_FILES['photo']['tmp_name'])){
$name = $_FILES['photo']['name'];
$uploadfile = $mainDir . $name;
move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile);
$lrgImg = $mainDir . $name;
$smlImg = $smalDir . $name;
$imageMagick = $command . " '". $lrgImg . "' -resize '$size' '" . $smlImg . "'";
shell_exec($imageMagick);
}
header("Location: /test.php");
exit;
}else{
&#63;>
" method="post" enctype="multipart/form-data">
<&#63;php
foreach(glob($smalDir.'*') as $img){
echo ' ';
}
}
&#63;>
希望本文所述对大家学习php程序设计有所帮助。
以上就介绍了php实现图片上传并利用ImageMagick生成缩略图,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。