开发者

ImageMagick/Perl sorting images by Pixel width/height

开发者 https://www.devze.com 2023-04-05 17:25 出处:网络
Hi I am having trouble finding any info on how to list images by pixel width or height with Image Magick. what I want to do is filter out images that are less than a specified size of pixel width or h

Hi I am having trouble finding any info on how to list images by pixel width or height with Image Magick. what I want to do is filter out images that are less than a specified size of pixel width or height. This is done through a perl sc开发者_StackOverflow社区ript and any help is appreciated.


Based on some code I use for other stuff:

use strict;
use warnings;

use Image::Magick;
use Win32::Autoglob;

my $max_cols = 640;
my $max_rows = 480;

IMAGE:
for my $image_name (@ARGV) {

    my $image = Image::Magick->new;
    my $result = $image->Read($image_name);
    die "Failed to read $image_name - $result" if $result;

    my ($cols, $rows) = $image->Get('columns', 'rows');

    next IMAGE if $cols > $max_cols;
    next IMAGE if $rows > $max_rows;

    # your processing here...

}


Use identify utility from ImageMagick to obtain width and height.


  1. Install the PerlMagick perl module from http://www.imagemagick.org/script/perl-magick.php

  2. Use code similar to the Example Script examples from that web page to read each image.

  3. Query the number of rows and columns in each image using $image->Get('rows') and $image->Get('columns') and skip images that are too small.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号