java的image magick问题

发布于 2024-09-08 11:11:22 字数 2001 浏览 5 评论 0原文

具体来说,我正在尝试在 java 上运行下一行:

 convert /home/mohamed.hegab/Desktop/1263392123111.jpg -gamma .45455 -resize 400x400 -gamma 2.2 -quality 92 /home/mohamed.hegab/Desktop/small.jpg

它在 bash 命令行上运行得很好 但是当我使用进程生成器在java上运行它时,它给了我奇怪的结果。

public static void resizeImage(String srcPath, String destPath,String size) {

        ProcessBuilder pb = new ProcessBuilder("convert", srcPath , " -gamma", ".45455",
                " -resize",size, " -gamma ", "2.2", " -quality",
                "92" , destPath);
        pb.redirectErrorStream(true);
        InputStreamReader isr = null;
        BufferedReader br = null;
        try {
            Process p = pb.start();
            p.waitFor();
            isr = new InputStreamReader(p.getInputStream());
            br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (Exception e) {
            LOG.error("Exception while trying to convert text to image", e);
        } finally {
            try {
                if(isr != null) {
                    isr.close();
                }
                if(br != null) {
                    br.close();
                }
            } catch (IOException e) {
                LOG.error("Could not close stream", e);
            }
        }
    }

system.out 中的行很奇怪,它说:


convert:无法打开图像-gamma':没有这样的文件或目录@ blob.c/OpenBlob/2439。 转换:无法打开图像.45455':没有这样的文件或目录@ blob.c/OpenBlob/2439。 转换:无法打开图像-resize':没有这样的文件或目录@ blob.c/OpenBlob/2439。 转换:无法打开图像400x400':没有这样的文件或目录@ blob.c/OpenBlob/2439。 转换:无法打开图像 -gamma ':没有这样的文件或目录@ blob.c/OpenBlob/2439。 转换:无法打开图像2.2':没有这样的文件或目录@ blob.c/OpenBlob/2439。 转换:无法打开图像-quality':没有这样的文件或目录@ blob.c/OpenBlob/2439。 转换:无法打开图像92':没有这样的文件或目录@ blob.c/OpenBlob/2439。


但图像只有 960 *960 的尺寸,我不知道它来自哪里。

那么任何人都可以帮助我吗:)

to be specific in this i'm trying to run the next line on java:

 convert /home/mohamed.hegab/Desktop/1263392123111.jpg -gamma .45455 -resize 400x400 -gamma 2.2 -quality 92 /home/mohamed.hegab/Desktop/small.jpg

which is run great on the bash command line
but when i run it on the java using process builder it gives me strange result.

public static void resizeImage(String srcPath, String destPath,String size) {

        ProcessBuilder pb = new ProcessBuilder("convert", srcPath , " -gamma", ".45455",
                " -resize",size, " -gamma ", "2.2", " -quality",
                "92" , destPath);
        pb.redirectErrorStream(true);
        InputStreamReader isr = null;
        BufferedReader br = null;
        try {
            Process p = pb.start();
            p.waitFor();
            isr = new InputStreamReader(p.getInputStream());
            br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (Exception e) {
            LOG.error("Exception while trying to convert text to image", e);
        } finally {
            try {
                if(isr != null) {
                    isr.close();
                }
                if(br != null) {
                    br.close();
                }
            } catch (IOException e) {
                LOG.error("Could not close stream", e);
            }
        }
    }

the line that comes in the system.out is strange and weird it says that


convert: unable to open image -gamma': No such file or directory @ blob.c/OpenBlob/2439.
convert: unable to open image
.45455': No such file or directory @ blob.c/OpenBlob/2439.
convert: unable to open image -resize': No such file or directory @ blob.c/OpenBlob/2439.
convert: unable to open image
400x400': No such file or directory @ blob.c/OpenBlob/2439.
convert: unable to open image -gamma ': No such file or directory @ blob.c/OpenBlob/2439.
convert: unable to open image
2.2': No such file or directory @ blob.c/OpenBlob/2439.
convert: unable to open image -quality': No such file or directory @ blob.c/OpenBlob/2439.
convert: unable to open image
92': No such file or directory @ blob.c/OpenBlob/2439.


but the images is comes out only with the size 960 *960 which i don't know where it comes from .

so can any one help me in this :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

游魂 2024-09-15 11:11:22

避免 - 之前的空格,shell 命令只能识别以 - 开头的选项。

Avoid the blanks before the -, shell commands can only recognize options that start with -.

○愚か者の日 2024-09-15 11:11:22

答案在此链接

http:// www.darcynorman.net/2005/03/15/jai-vs-imagemagick-image-resizing/

只是我应该将命令切成数组中的片段并在没有进程生成器的情况下正常运行它

the answer is here in this link

http://www.darcynorman.net/2005/03/15/jai-vs-imagemagick-image-resizing/

simply i should cut the command to pieces in array and run it normally without process builder

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文