TOP ▲
itcore TOP
> TIPS
> img_index.php
タグ:画像 imagemagick サムネイル ディレクトリ配下の画像一覧を表示。サムネイル画像作成。クリックでオリジナル画像表示。 | itcore 2018年
環境設定
ディレクトリ作成
# mkdir img_index
パーミッション変更
centos
# chown apache.apache img_index
ubuntu
# chown www-data.www-data img_index
imagemagicインストール
yum -y install ImageMagick
yum -y install ImageMagick-devel
画像をアップロード
img_index/xxx.jpg
テスト
表示
プログラムソース
<?php
print "<html><head><title>img_index.php </title></head><body><a href=..>上へ</a> 写真をクリックすると拡大表示されます。</br>\n";
$a = array();
if ($dh = opendir(".")) {
while (($file = readdir($dh)) !== false) {
#echo "file=$file<br>";
if (substr($file, 0, 1) == ".") continue;
$ext = substr($file, -4);
$ext = mb_strtolower($ext);
#if (".jpg" == $ext || ".gif" == $ext || ".png" == $ext) {
if (".jpg" == $ext) {
#echo "file2=$file<br>";
$file300 = $file . "300";
if (false === file_exists($file300)) {
$cmd = "convert -resize 300x $file $file300";
echo "$cmd<br>\n";
uFlush(); // 画面出力 画面スクロール
exec($cmd);
}
$a[] = $file;
}
}
}
closedir($dh);
#$a = array("20161113_125425.jpg300");
#echo exec("pwd") . "<br>\n";
#exec("convert -resize 300x 20161113_125425.jpg 20161113_125425.jpg300");
sort($a);
foreach($a as $key => $value) {
#echo "file3=$value<br>";
print "<a href=\"$value\" TARGET=jpg><IMG SRC=\"$value" . "300\"></a>";
}
// 処理の途中で画面を表示させる。画面を一番下へスクロールする。
function uFlush() {
print "<script>window.scrollTo(0, document.body.clientHeight);</script>\n"; // 一番下へスクロール
ob_flush(); // 出力バッファをフラッシュ(送信)する
flush(); // システム出力バッファをフラッシュする。
}
?>