Beispiel #1
0
function GetFileInfo($filename, $ext, $dir = false)
{
    $result = "";
    if ($dir) {
        $result = " ";
    } else {
        switch ($ext) {
            case "png":
            case "gif":
            case "jpg":
                $imginfo = image_info($filename);
                $result = $imginfo["width"] . "x" . $imginfo["height"] . "x" . $imginfo["bits"];
                break;
            default:
                $result = " ";
        }
    }
    return $result;
}
Beispiel #2
0
<?php

// カレントディレクトリ配下の接尾語 "_RE" を除いたJPGファイルを並べるだけ
// 各端末のブラウザで画像を見比べたいから作った
// LANでの使用のみ想定してるのでセキュリティとか皆無
$target_dir = '.';
if (!is_dir($target_dir)) {
    throw new Exception('directory is not found.');
}
// "_RE" ファイル除外
$result = image_info(array_filter(list_files($target_dir, ['jpg']), function ($val) {
    return !preg_match('/_RE\\.jpg/', $val);
}));
// "_RE" ファイルが無いものを除外
$result = array_filter($result, function ($val) {
    return $val['retouch_file'];
});
function image_info(array $files)
{
    $list = [];
    foreach ($files as $path) {
        list($w, $h) = getimagesize($path);
        $list[] = ['path' => $path, 'filename' => basename($path), 'w' => $w, 'h' => $h, 'orientation' => $w < $h ? 1 : 0, 'retouch_file' => retouch_file_exists($path)];
    }
    return $list;
}
function retouch_file_exists($path)
{
    $retouch_file = preg_replace('/\\.jpg/', '_RE.jpg', $path);
    return $retouch_file !== $path && is_file($retouch_file) ? $retouch_file : '';
}