Home > php教程 > php手册 > body text

php实现图片上传并利用ImageMagick生成缩略图,

WBOY
Release: 2016-06-13 08:44:31
Original
1459 people have browsed it

php实现图片上传并利用ImageMagick生成缩略图,

使用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;>
<form action=" <&#63;php echo $_SERVER['PHP_SELF']; &#63;> " method="post" enctype="multipart/form-data">
<p><input type="file" name="photo" /></p>
<p><input type="submit" value="Upload!" name="submit" /></p>
</form>
<&#63;php
foreach(glob($smalDir.'*') as $img){
echo ' <img  src="'.str_replace($_SERVER['DOCUMENT_ROOT'], '',$img).'" / alt="php实现图片上传并利用ImageMagick生成缩略图," > ';
}
}
&#63;>
Copy after login

希望本文所述对大家学习php程序设计有所帮助。

您可能感兴趣的文章:

  • PHP图片上传类带图片显示
  • 简单的PHP图片上传程序
  • php 图片上传类代码
  • 超级好用的一个php上传图片类(随机名,缩略图,加水印)
  • PHP 图片上传代码
  • PHPThumb PHP 图片缩略图库
  • thinkphp实现图片上传功能分享
  • php实现的支持imagemagick及gd库两种处理的缩略图生成类
  • php多个文件及图片上传实例详解
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template