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

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

本文介绍了如何使用命令行PHP程序查看jpg图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to view jpg images within command line PHP?

我想通过一个命令行PHP程序中的照片目录循环,并使用php stdin,对这张照片采取行动,如将其移动到另一个目录。我没有能够找到一个方法从命令行PHP输出每个图像。

I would like to loop thru a directory of photos within a command line PHP program and use a keystroke, by utilizing php stdin, to take an action on that photo, like move it to another directory. I have not been able to locate a method to output each image from command line PHP.

感谢

这里是我到目前为止的代码。如果我可以查看jpg我想我可以确定...

Here is the code I have thus far. If I can view the jpg I think I might be ok …

<?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
}

?>


推荐答案

我最后使用open命令打开Preview中的图片

I ended up using the "open" command which opens the image in "Preview"

看起来像qlmanage也可能是一个选项。我无法让ImageMagick工作。它似乎需要安装X11,这在最近几个版本中没有被包括在OS X中。 Apple支持页面指向xquartz作为在操作系统X11上安装X11的网站。我安装它,但在摔跤的设置和Imagemagick环顾更多,发现打开。感谢

It looks like "qlmanage" might also be an option. I could not get ImageMagick to work. It seems to require X11 be installed, which has not been included in OS X in the last few versions. The Apple support page points to "xquartz" as a site from which to install X11 on OS X. I installed it but after wrestling with its setup and Imagemagick looked around more and found "open". thanks

这篇关于如何使用命令行PHP程序查看jpg图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 05:45