"=?WINDOWS-1252?Q?Stano_Pa=9Aka?=" on  wrote...
| Hi,
| 
| it is possible to resize image differently when it is oriented
| landscape or portrait?
| 
| I need create thumbnails 104x80 from landscape or portrait sized images.
| 
| Once I have it done with creating extra borders for portraits, but now
| I must done it with cropping.
| 
| Example:
| input: 500x300, resized to 133x80, cropped to 104x80
| input: 300x500, resized ro 104x173, cropped to 104x80
| 
| I need something like -rezise 104x104 but not 104 as maximum values
| but minimum values, other side may be larger and I crop it exact to
| 104x80
| 
| It is possible with one commandline for all cases?
| 

I thought about it but...  NO it is not posible
And command line while it can do a lot of hightly complex tasks
can only do ONE sequence of operations.
It has no  IF-ELSE   FOR-WHILE-UNTIL  type controls.

Your options are to go into "conjure" a XML parsed API
or better still into PerlMagick or PHP-Magick  or C++Magick

The perl one is not too bad, and command line sequences can often be
directly converted into into PerlMagick Sequences.
(Actutally that would be a Nice Perl Module :-)


For example.... This I pulled out of a 'image comparision' script
I am currently experimenting with, to find 'simular images'.

It contains both "Run Command" version and a PerlMagick Verion.

If you study it, other than the initial "Read Image", and the final
"Extract Pixels"  there is a direct correspondance between the command line
version, and the PerlMagick image operators.

Actually after timing this over a 100 images, I found little difference
between using a PerlMagick vs CommandLine basically due to the speed of
the Image processing options, verses the 'command fork' overhead.

=======8<--------CUT HERE----------axes/crowbars permitted---------------
#
# Convert image to a small 3x3 greyscale metric
#
sub get_metric {
  my( $f ) = @_;

  if( 1 ) {   # Run Command Line, or PerlMagick version?
    #
    #  Command Line Version
    #
    open( CMD, '-|', 'convert', $f,
          qw( -gravity center -crop 80x80%+0+0 ),        # remove border
          qw( -scale 100x100! -blur 0x2 +dither -colors 3 ), # simplify (fast)
          qw( -edge 1 -colorspace Gray ),                # find edges
          qw( -blur 0x2 -scale 3x3 ),                    # 3x3 matrix metric
          qw( -compress none pgm:- )                     # output colors
        ) or die "Failed to run convert on \"$f\"\n";
    $_ = join('', <CMD>);
    close( CMD );
    s/.*\n\s+//s; # reduce it to just the image data.
    s/\s*$//s;    # clean up the end
    return $_;
  }

  #
  # PerlMagick Version
  #

  # Read in the image...
  my $i=Image::Magick->new;
  my $w = $i->Read(filename=>$f);
  if ( $w =~ /^Exception 4..: / ) {
    #$w =~ s/ `[^']*'//;
    warn("$f: $w\n");
    return undef;
  } else {
    warn("$f: $w\n")  if $w;
  }

  # Strip some rows and columns
  my ($x, $y) = $i->Get( qw( columns rows ) );
  $w = $i->Shave(width=>$x/10, height=>$y/10);  # remove pixels from edges
  warn("$w\n")  if $w;
  return undef  if $w =~ /^Exception/;

  if ( $metric = 'EdgeMatrix' ) {

    $w = $i->Scale( geometry => '100x100!' ); # scale to working size
    warn("$f: scale: $w\n")  if $w;
    return undef if $w =~ /^Exception/;

    $w = $i->Blur( geometry => '0x2' );       # forget small details
    warn("$f: blur: $w\n")  if $w;
    return undef if $w =~ /^Exception/;

    $w = $i->Quantize( colors => 3, dither => 0 );    # simplify color areas
    warn("$f: quantize: $w\n")  if $w;
    return undef if $w =~ /^Exception/;

    $w = $i->Edge( radius => 1 );             # get edges
    warn("$f: scale: $w\n")  if $w;
    return undef if $w =~ /^Exception/;

    $w = $i->Set( colorspace => 'Gray' );     # make them greyscale
    warn("$f: gray: $w\n")  if $w;
    return undef if $w =~ /^Exception/;

    $w = $i->Blur( geometry => '0x2' );      # spead edges a bit
    warn("$f: blur: $w\n")  if $w;
    return undef if $w =~ /^Exception/;

    #$i->Display();

    $w = $i->Scale( geometry => '3x3!' );    # make 3x3 matrix mertic
    warn("$f: scale: $w\n")  if $w;
    return undef if $w =~ /^Exception/;

    return  join(' ', $i->GetPixels( map=>'R', height=>3, width=>3 ) );
  }
}
=======8<--------CUT HERE----------axes/crowbars permitted---------------

  Anthony Thyssen ( System Programmer )    <[EMAIL PROTECTED]>
 -----------------------------------------------------------------------------
               Copyright 19.... ah hell, just take it.
                  Jeffrey Friedl   Perl   Dec 1994.
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to