利用imagemagick來作縮圖
Posted royal_coffee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了利用imagemagick來作縮圖相关的知识,希望对你有一定的参考价值。
此方式是經由站長建議來實作的喔..
那天與站長閒聊GD與系統縮圖程式的優缺點.
經小弟省思許多還是贊同站長的建議...
利用imagemagick與php來作搭配..
果然...方便渡給100分喔..
小弟提供一個簡單的語法範例功大家一起研究..
有錯誤請多指正唷..^_^
<?
php
$w = " 240 " ; // 自行設定的縮圖寬度
$h = " 320 " ; // 自行設定的縮圖高度
if ( $_FILES [ ' file ' ][ ' type ' ] == " image/pjpeg " || $_FILES [ ' file ' ][ ' type ' ] == " image/gif " || $_FILES [ ' file ' ][ ' type ' ] == " image/png " ) {
if ( $_FILES [ ' file ' ][ ' type ' ] == " image/pjpeg " ) {
$filename = substr ( rand ( 0 , 999999999999 ) , 1 , 7 ) . " .gif " ; // 隨機取檔名..我的習慣啦 ^^||
}
if ( $_FILES [ ' file ' ][ ' type ' ] == " image/gif " ) {
$filename = substr ( rand ( 0 , 999999999999 ) , 1 , 7 ) . " .gif " ;
}
if ( $_FILES [ ' file ' ][ ' type ' ] == " image/png " ) {
$filename = substr ( rand ( 0 , 999999999999 ) , 1 , 7 ) . " .png " ;
}
$size = $w . " x " . $h ;
copy ( $_FILES [ ' file ' ][ ' tmp_name ' ] , " /home/caisse/case/kf/data/file/b " . $filename ); // 將暫存檔copy至自己定義的目錄..因為小弟大小圖都想要 ^^
$big_image = " /home/caisse/case/kf/data/file/b " . $filename ;
$small_image = " /home/caisse/case/kf/data/file/s " . $filename ;
$exec_str = " /usr/bin/convert '-geometry' " . $size . " " . $big_image . " " . $small_image ; // 注意"跟'唷
exec ( $exec_str );
} else {
echo " 請上傳圖片 " ;
}
?>
< form action = " # " method = " post " enctype = " multipart/form-data " name = " form1 " >
< input type = " file " name = " file " >
< input type = " submit " name = " Submit " value = " 送出 " >
</ form >
<? php if ( $_FILES ) { ?>
原始圖 < img src = " /data/file/b<?php echo $filename; ?> " > < br >
裁切後的圖 < img src = " /data/file/s<?php echo $filename; ?> " >
<? php } ?>
$w = " 240 " ; // 自行設定的縮圖寬度
$h = " 320 " ; // 自行設定的縮圖高度
if ( $_FILES [ ' file ' ][ ' type ' ] == " image/pjpeg " || $_FILES [ ' file ' ][ ' type ' ] == " image/gif " || $_FILES [ ' file ' ][ ' type ' ] == " image/png " ) {
if ( $_FILES [ ' file ' ][ ' type ' ] == " image/pjpeg " ) {
$filename = substr ( rand ( 0 , 999999999999 ) , 1 , 7 ) . " .gif " ; // 隨機取檔名..我的習慣啦 ^^||
}
if ( $_FILES [ ' file ' ][ ' type ' ] == " image/gif " ) {
$filename = substr ( rand ( 0 , 999999999999 ) , 1 , 7 ) . " .gif " ;
}
if ( $_FILES [ ' file ' ][ ' type ' ] == " image/png " ) {
$filename = substr ( rand ( 0 , 999999999999 ) , 1 , 7 ) . " .png " ;
}
$size = $w . " x " . $h ;
copy ( $_FILES [ ' file ' ][ ' tmp_name ' ] , " /home/caisse/case/kf/data/file/b " . $filename ); // 將暫存檔copy至自己定義的目錄..因為小弟大小圖都想要 ^^
$big_image = " /home/caisse/case/kf/data/file/b " . $filename ;
$small_image = " /home/caisse/case/kf/data/file/s " . $filename ;
$exec_str = " /usr/bin/convert '-geometry' " . $size . " " . $big_image . " " . $small_image ; // 注意"跟'唷
exec ( $exec_str );
} else {
echo " 請上傳圖片 " ;
}
?>
< form action = " # " method = " post " enctype = " multipart/form-data " name = " form1 " >
< input type = " file " name = " file " >
< input type = " submit " name = " Submit " value = " 送出 " >
</ form >
<? php if ( $_FILES ) { ?>
原始圖 < img src = " /data/file/b<?php echo $filename; ?> " > < br >
裁切後的圖 < img src = " /data/file/s<?php echo $filename; ?> " >
<? php } ?>
以上是关于利用imagemagick來作縮圖的主要内容,如果未能解决你的问题,请参考以下文章
php安装imagemagick扩展 常见问题与解决方案(win平台)
六 sublime 颜色插件 Color Highlighter&Gutter Color&ImageMagick
安全-ImageMagick 小于等于6.9.3-9版本 命令执行漏洞复现(i春秋)