php实现图片上传并利用ImageMagick生成缩略图
程序员文章站
2023-12-12 08:23:28
使用imagemagick,您可以轻松,更快地创建缩略图,比使用php的容易得多。
使用imagemagick,您可以轻松,更快地创建缩略图,比使用php的容易得多。
<?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{ ?> <form action=" <?php echo $_server['php_self']; ?> " method="post" enctype="multipart/form-data"> <p><input type="file" name="photo" /></p> <p><input type="submit" value="upload!" name="submit" /></p> </form> <?php foreach(glob($smaldir.'*') as $img){ echo ' <img src="'.str_replace($_server['document_root'], '',$img).'" /> '; } } ?>
希望本文所述对大家学习php程序设计有所帮助。
推荐阅读