ben
ben

Reputation: 21

ImageMagick/Perl sorting images by Pixel width/height

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 script and any help is appreciated.

Upvotes: 2

Views: 972

Answers (3)

Bill Ruppert
Bill Ruppert

Reputation: 9016

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...

}

Upvotes: 3

Simon C
Simon C

Reputation: 2017

  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.

Upvotes: 0

Nikolay Polivanov
Nikolay Polivanov

Reputation: 677

Use identify utility from ImageMagick to obtain width and height.

Upvotes: 0

Related Questions