Thread GD::Image Bilder verkleinern (3 answers)
Opened by ST3V3N at 2018-08-08 18:04

GwenDragon
 2018-08-08 18:50
#188752 #188752
User since
2005-01-17
14510 Artikel
Admin1
[Homepage]
user image
CPAN:Image::Resize (benutzt GD); siehe https://metacpan.org/pod/Image::Resize#METHODS und Quelle: https://metacpan.org/source/SHERZODR/Image-Resize-...

Schaust du wie das Modul das macht bei resize() (Zeile 37):
more (16.7kb):
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package Image::Resize;
 
# $Id: Resize.pm,v 1.5 2005/11/04 23:44:59 sherzodr Exp $
 
use strict;
use Carp ('croak');
use GD;
 
$Image::Resize::VERSION = '0.5';
 
# Thanks to Paul Allen <paul.l.allen AT comcast.net> for this tip
GD::Image->trueColor( 1 );
 
sub new {
    my ($class, $image) = @_;
    unless ( $class && defined($image) ) { croak "Image::Resize->new(): usage error"; }
    my $gd;
 
    # Thanks to Nicholas Venturella <nick2588 AT gmail.com> for this tip
    if (ref($image) eq "GD::Image") {
        $gd = $image;
 
    } else {
        unless ( -e $image ) { croak "Image::Resize->new(): file '$image' does not exist"; }
        $gd = GD::Image->new($image) or die $@;
    }
 
    return bless {
        gd => $gd
    }, $class;
}
 
sub width   { return ($_[0]->gd->getBounds)[0]; }
sub height  { return ($_[0]->gd->getBounds)[1]; }
sub gd      { return $_[0]->{gd}; }
 
sub resize {
    my $self = shift;
    my ($width, $height, $constraint) = @_;
    unless ( defined $constraint ) { $constraint = 1; }
    unless ( $width && $height ) { croak "Image::Resize->resize(): usage error"; }
 
    if ( $constraint ) {
        my $k_h = $height / $self->height;
        my $k_w = $width / $self->width;
        my $k = ($k_h < $k_w ? $k_h : $k_w);
        $height = int($self->height * $k);
        $width  = int($self->width * $k);
    }
 
    my $image = GD::Image->new($width, $height);
    $image->copyResampled($self->gd,
        0, 0,               # (destX, destY)
        0, 0,               # (srcX,  srxY )
        $width, $height,    # (destX, destY)
        $self->width, $self->height
    );
    return $image;
}
 
 
1;
__END__
und baust das resize() in deinem Programm selbst nach.
Last edited: 2018-08-08 18:54:41 +0200 (CEST)
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread GD::Image Bilder verkleinern