[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: offtopic: cutting an image into subimages...



On Mon, May 15, 2006 at 10:11:17AM +0200, Florian Kulzer wrote:
> On Mon, May 15, 2006 at 09:39:20 +0200, Bruno Boettcher wrote:
> > Hello!
> > 
> > might be offtopic, but i don't know where to post this one...
> > 
> > for a website i need to cut down into 9 parts an image, and repeat 3
> > times this operation with the subimages.
> > 
> > Then i need to reduce the resolution in the inverse sense, making the
> > big scans smaller.....
> > 
> > this is to make a html map system...
> > 
> > if there was some automated way to do this?
> 
> ImageMagick can do such things. It offers very powerful command line
> tools, but it is sometimes a bit difficult to choose from all the
> available options. For your problem, have a look at this:
> 
> http://www.cit.gu.edu.au/~anthony/graphics/imagick6/crop/#crop_tile

I wrote a bit of perl to process "multi-16" mode pictures from a Nikon
camera, where a 4x4 grid of images is stored in a single frame.  This uses
ImageMagick identify and convert -crop to separate the 16 images.  I'm not
sure if you're referring to a 3x3 grid(s), but if so then perhaps this
might be useful.

    $ cat `which multi16-split`
    #!/usr/bin/perl -w
    use strict;
    my $image = shift or die;
    my $identify = `identify $image`;
    my ($sizex, $sizey) = $identify =~ m/(\d+)x(\d+)/;
    my ($cropx, $cropy) = ($sizex/4, $sizey/4);
    printf "%sx%s, %sx%s\n", $sizex, $sizey, $cropx, $cropy;
    my $n = "00";
    my ($out) = $image =~ m{([^/]+).jpg};
    for ( my $y=0; $y<$sizey; $y+=$sizey/4 ) {
        for ( my $x=0; $x<$sizex; $x+=$sizex/4 ) {
            my $outfile = sprintf "$out-%02d.jpg", $n++;
            print  "convert -crop 25\%x25\%+$x+$y $image $outfile", "\n";
            system "convert -crop 25\%x25\%+$x+$y $image $outfile";
            }
        }

I don't think you need to have separate images for html mapping to work,
though.

-- 
Ken Irving



Reply to: