Quiq

 view release on metacpan or  search on metacpan

lib/Quiq/Gd/Image.pm  view on Meta::CPAN


=head1 METHODS

=head2 Konstruktor

=head3 new() - Instantiiere Bildobjekt

=head4 Synopsis

  $img = $class->new($file);
  $img = $class->new($data);
  $img = $class->new($width,$height);
  $img = $class->new($width,$height,$maxColors);

=head4 Returns

Bildobjekt

=head4 Description

Instantiiere ein Bildobjekt der Breite $width und der Höhe $height mit
einer maximalen Anzahl von $maxColors Farben und liefere eine
Referenz auf dieses Objekt zurück. Schlägt der Aufruf fehl, löse
eine Exception aus.

Ist $maxColors nicht angegeben oder $maxColors > 256, wird ein
TrueColor-Bild erzeugt, andernfalls ein palette-basiertes Bild
mit maximal 256 Farben.

Die Methode blesst das Objekt auf die Klasse $class, da die Methoden
newPalette() und newTrueColor() der Klasse GD::Image dies nicht tun!

Der Hintergrund eines TrueColor-Bildes ist schwarz. Eine andere
Hintergrundfarbe wird mit background() gesetzt. Anders als
bei einem palette-basierten Bild ist I<nicht> die erste allozierte
Farbe die Hintergrundfarbe!

=head4 See Also

Siehe "perldoc GD", Methoden newPalette(), newTrueColor().

=cut

# -----------------------------------------------------------------------------

sub new {
    my $class = shift;
    # my @args = @_; # @args wird nur im Fehlerfall gebraucht
    # @_: s.u.

    my $self;
    if (@_ == 1) { # $file -or- $data
        $self = $class->SUPER::new(shift);

        #my $file = shift;
        #
        #if ($file =~ /\.jpg$/i) {
        #    $self = $class->newFromJpeg($file,1);
        #}
        #elsif ($file =~ /\.png$/i) {
        #    $self = $class->newFromPng($file,1);
        #}
        #else {
        #    $class->throw(
        #        'GD-00005: Unbekannter Dateityp',
        #        File => $file,
        #    );
        #}
    }
    else { # $width,$height,$color
        my $width = shift;
        my $height = shift;
        my $colors = shift;

        if ($colors && $colors <= 256) {
            # Palettebasiertes Bild mit max. 256 Farben
            $self = $class->SUPER::newPalette($width,$height);
        }
        else {
            # TrueColor-Bild
            $self = $class->SUPER::newTrueColor($width,$height);
        }
    }
    unless ($self) {
        $class->throw(
            'GD-00001: Konstruktoraufruf fehlgeschlagen',
            # ConstructorArguments => "[@args]",
        );
    }

    return bless $self,$class;
}

# -----------------------------------------------------------------------------

=head2 Klassenmethoden

=head3 textImage() - Erzeuge Bild mit Text

=head4 Synopsis

  $img = $class->textImage($text,@opt);

=head4 Arguments

=over 4

=item $text

Text, der in das Bild geschrieben wird.

=back

=head4 Options

=over 4

=item -background => $color (Default: 'white')

Hintergrundfarbe.



( run in 2.979 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )