如何使用命令行PHP程序查看jpg图像


How to view jpg images with a command line PHP program

有没有办法在命令行PHP中查看jpg图像?

我想在命令行PHP程序中循环浏览照片目录,并使用击键,通过利用php stdin对该照片进行操作,例如将其移动到另一个目录。我无法找到从命令行PHP输出每个图像的方法。

谢谢

这是我到目前为止的代码。如果我能查看jpg,我想我可能没事...

<?php
// View the jpg images one at a time
$files = glob("images/*.jpg");
foreach($files as $jpg){
//    echo "<img src='$jpg'></br>";
  echo "view image somehow" . PHP_EOL;
echo "The jpg variable equals '$jpg'" . PHP_EOL;
// show them a message to enter letter for category
echo "Enter the category, a(family), r(friends), c(coworkers), d(delete), ctrl-letter(two folders)" . PHP_EOL;
// the script will wait here until the user has entered something and hit ENTER
$category = read_stdin();
// This will display the category message including the category they entered.
echo "You chose $category . Next photo" . PHP_EOL;
switch ($category) {
    case "a":
        echo "$category equals family" . PHP_EOL;
        r    ename("$jpg", "images/sorted/family/$jpg");
        break;
    case "r":
        echo "$category equals friends" . PHP_EOL;
        rename("$jpg", "images/sorted/friends/$jpg");
        break;
    case "c":
        echo "$category equals coworkers" . PHP_EOL;
        rename("$jpg", "images/sorted/coworkers/$jpg");
        break;
    default:
       echo "$category is not equal to a,r, or c" . PHP_EOL;
 }
}
// our function to read from the command line
function read_stdin()
{
        $fr=fopen("php://stdin","r");   // open our file pointer to read from stdin
        $input = fgets($fr,128);        // read a maximum of 128 characters
        $input = rtrim($input);         // trim any trailing spaces.
        fclose ($fr);                   // close the file handle
        return $input;                  // return the text entered
}
?>

你给我发了关于ImageMagick"display"的邮件。

您可以做的是在后台运行"显示",然后使用"-remote"向其发送图片和更新以显示。 我已经在Linux下使用shell脚本完成了此操作,尽管我认为"显示"在Windows上的工作方式不同。

有关远程控制各种图像程序的一些想法,请参阅我的原始注释(仅适用于linux)http://www.ict.griffith.edu.au/anthony/info/X/Image_Remote_Control.txt

我最终使用了"打开"命令,该命令在"预览"中打开图像

看起来"qlmanage"也可能是一种选择。我无法让ImageMagick工作。它似乎需要安装 X11,这在最近几个版本中尚未包含在 OS X 中。Apple 支持页面指向"xquartz"作为在 OS X 上安装 X11 的站点。我安装了它,但在与它的设置和 Imagemagick 搏斗之后,环顾四周,发现"打开"。谢谢