简体   繁体   English

如何使用ImageMagick API在Perl中编写此命令行命令?

[英]How can I write this command line command in Perl using the ImageMagick API?

How can I do the same as the following command line command in Perl using the ImageMagick API? 如何使用ImageMagick API与Perl中的以下命令行命令相同?

convert scotland.jpg[1x1+0+0] -depth 8 txt:

The result should look similar to this: 结果应类似于以下内容:

# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: ( 48, 50, 47)  #30322F  rgb(48,50,47)

I found an explanation in Perl & Image::Magick, getting color values by pixel and lifted/changed the code. 我在Perl&Image :: Magick中找到了解释, 按像素获取颜色值并提升/更改了代码。 This works for me: 这对我有用:

use strict; use warnings;
use Data::Dumper; 
use Image::Magick; 

my $img = Image::Magick->new; 
$img->Read("foo.jpg");

my @pixel = $img->GetPixels(
  width  => 1,
  height => 1,
  x      => 0,
  y      => 0,
  map    => "RGB"
);

print Dumper \@pixel;

As said by brian in his answer to the linked question, you may need to reduce the depth. 正如布赖恩在回答链接问题时所说的那样,您可能需要减少深度。 See the other question for details. 有关详细信息,请参见另一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM