~ubuntu-branches/debian/squeeze/movabletype-opensource/squeeze

« back to all changes in this revision

Viewing changes to lib/MT/Image.pm

  • Committer: Bazaar Package Importer
  • Author(s): Dominic Hargreaves
  • Date: 2009-06-19 23:03:15 UTC
  • mfrom: (1.2.1 upstream) (9.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090619230315-rm1vcgg5iymu2zh1
Tags: 4.2.6.1-1
* New upstream release
* Update Standards-Version (no changes)
* Don't specify full path to apache2ctl in postinst (thanks, Lintian)
* Remove unused Lintian overrides
* Don't install empty directory in extlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
 
1
# Movable Type (r) Open Source (C) 2001-2009 Six Apart, Ltd.
2
2
# This program is distributed under the terms of the
3
3
# GNU General Public License, version 2.
4
4
#
5
 
# $Id: Image.pm 2747 2008-07-10 17:16:23Z bchoate $
 
5
# $Id: Image.pm 3455 2009-02-23 02:29:31Z auno $
6
6
 
7
7
package MT::Image;
8
8
 
269
269
    my $type = $image->{type};
270
270
    my($out, $err);
271
271
    my $pbm = $image->_find_pbm or return;
272
 
    my @in = ("$pbm${type}topnm", ($image->{file} ? $image->{file} : ()));
 
272
    my @in = ("$pbm${type}topnm", ($image->{data} ? () : $image->{file} ? $image->{file} : ()));
273
273
    my @scale = ("${pbm}pnmscale", '-width', $w, '-height', $h);
274
274
    my @out;
275
275
    for my $try (qw( ppm pnm )) {
280
280
    if ($type eq 'gif') {
281
281
        push @quant, ([ "${pbm}ppmquant", 256 ], '|');
282
282
    }
283
 
    IPC::Run::run(\@in, '<', ($image->{file} ? \undef : \$image->{data}), '|',
 
283
    IPC::Run::run(\@in, '<', ($image->{data} ? \$image->{data} : \undef ), '|',
284
284
        \@scale, '|',
285
285
        @quant,
286
286
        \@out, \$out, \$err)
287
287
        or return $image->error(MT->translate(
288
288
            "Scaling to [_1]x[_2] failed: [_3]", $w, $h, $err));
289
 
    ($image->{width}, $image->{height}) = ($w, $h);
 
289
    ($image->{width}, $image->{height}, $image->{data}) = ($w, $h, $out);
290
290
    wantarray ? ($out, $w, $h) : $out;
291
291
}
292
292
 
294
294
    my $image = shift;
295
295
    my %param = @_;
296
296
    my ($size, $x, $y) = @param{qw( Size X Y )};
297
 
    
 
297
 
298
298
    my($w, $h) = $image->get_dimensions(@_);
299
299
    my $type = $image->{type};
300
300
    my($out, $err);
301
301
    my $pbm = $image->_find_pbm or return;
302
 
    my @in = ("$pbm${type}topnm", ($image->{file} ? $image->{file} : ()));
 
302
    my @in = ("$pbm${type}topnm", ($image->{data} ? () : $image->{file} ? $image->{file} : ()));
303
303
 
304
304
    my @crop = ("${pbm}pnmcut", $x, $y, $size, $size);
305
305
    my @out;
311
311
    if ($type eq 'gif') {
312
312
        push @quant, ([ "${pbm}ppmquant", 256 ], '|');
313
313
    }
314
 
    IPC::Run::run(\@in, '<', ($image->{file} ? \undef : \$image->{data}), '|',
 
314
    IPC::Run::run(\@in, '<', ($image->{data} ? \$image->{data} : \undef), '|',
315
315
        \@crop, '|',
316
316
        @quant,
317
317
        \@out, \$out, \$err)
318
318
        or return $image->error(MT->translate(
319
319
            "Cropping to [_1]x[_1] failed: [_2]", $size, $err));
320
 
    ($image->{width}, $image->{height}) = ($w, $h);
 
320
    ($image->{width}, $image->{height}, $image->{data}) = ($w, $h, $out);
321
321
    wantarray ? ($out, $w, $h) : $out;
322
322
}
323
323
 
330
330
 
331
331
    my($out, $err);
332
332
    my $pbm = $image->_find_pbm or return;
333
 
    my @in = ("$pbm${type}topnm", ($image->{file} ? $image->{file} : ()));
 
333
    my @in = ("$pbm${type}topnm", ($image->{data} ? () : $image->{file} ? $image->{file} : ()));
334
334
 
335
335
    my @out;
336
336
    for my $try (qw( ppm pnm )) {
341
341
    if ($type eq 'gif') {
342
342
        push @quant, ([ "${pbm}ppmquant", 256 ], '|');
343
343
    }
344
 
    IPC::Run::run(\@in, '<', ($image->{file} ? \undef : \$image->{data}), '|',
 
344
    IPC::Run::run(\@in, '<', ($image->{data} ? \$image->{data} : \undef ), '|',
345
345
        @quant,
346
346
        \@out, \$out, \$err)
347
347
        or return $image->error(MT->translate(
348
348
            "Converting to [_1] failed: [_2]", $type, $err));
 
349
    $image->{data} = $out;
349
350
    $out;
350
351
}
351
352