Thread Was will mir dieser Fehler sagen? gd-jpeg: cannot allocate gdImage struct
(16 answers)
Opened by roooot at 2008-11-19 15:48
Hi,
ich verkleinere Bilder mittels Image::Resize. Das funktioniert in einem kleinen Testscript 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 #!/usr/bin/perl -w use strict; use Carp; ### extend @INC use lib ( './', ); use CGI qw(:standard); use Image::Resize; for(1..10) { my $image = Image::Resize->new(qq{in$_.jpg}); my $gd = $image->resize(800, 800); open(FH, qq{>out$_.jpg}); print FH $gd->jpeg(); close(FH); my $gd = $image->resize(50, 40, 0); open(FH, qq{>thumb$_.jpg}); print FH $gd->jpeg(); close(FH); } print CGI::header(); print "resize: finish"; wunderbar. Bei meinem Hauptscript (siehe unten) kommt hingegen bei den gleichen Bildern dieser Fehler Code: (dl
)
1 [Wed Nov 19 14:44:12 2008] [error] [client **********] gd-jpeg error: cannot allocate gdImage struct Andere Bilder mit anderen Abmessungen funktionieren aber 1a im Hauptscript. Allerdings kann es ja kein memory Fehler sein, weil da hatte ich immer eine insufficent memory o.s.ä Fehler, nicht aber diesen. Danke für eure Hilfe 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 sub save { my ($self) = @_; ### get file my $file = $file_of{ident $self}; ##################################################### # currently quit because of error: # # Undefined subroutine Fh::seek # # at module/CPAN/File/MMagic.pm line 802 # ##################################################### ### check if file is jpeg # require File::MMagic; # require FileHandle; # my $mm = new File::MMagic; # my $file_mimetype = $mm->checktype_filehandle($file); # # print CGI::header(); # print qq{mimetype $file_mimetype}; # exit; ### get file hash - method sha1 require Digest::SHA1; my $sha1 = Digest::SHA1->new; $sha1->add($file); my $file_hash = $sha1->hexdigest; ### get gallery securestring require Gallery::Gallery; my $gal_securestring = new Gallery::Gallery({ 'Gallery' => { parameters => $self->get_params(), session => $self->get_session(), domain => $self->get_domain(), }, 'Gallery::Gallery' => { id => $self->get_id(), }, })->get_securestring($self->get_id()); ### check if gid exists if($gal_securestring eq 'notfound') { print CGI::header(); print qq{Cant save: gal_securestring for $self->get_id() not found}; exit; } ### save orig picture open my $ORIG, qq{>./pictures/$gal_securestring/org-$file_hash.jpg} or carp qq{Cant save orig: $!}; binmode $ORIG; binmode $file; my $data; while(read $file,$data,1024) { print $ORIG $data; } close $ORIG; ### resize picture use Image::Resize; my $image = Image::Resize->new(qq{./pictures/$gal_securestring/org- $file_hash.jpg}); ### picture for default view my $gd = $image->resize(800, 800); open my $PIC, qq{>./pictures/$gal_securestring/$file_hash.jpg} or carp qq{Cant save: $!}; print $PIC $gd->jpeg(); close $PIC; ### thumb $gd = $image->resize(50, 40, 0); open my $THUMB, qq{>./pictures/$gal_securestring/th-$file_hash.jpg} or carp qq{Cant save thumb: $!}; print $THUMB $gd->jpeg(); close $THUMB; ### get picture ratio require GD::Simple; $image = GD::Simple- >newFromJpeg(qq{./pictures/$gal_securestring/$file_hash.jpg},1) or print qq{Cant read image for ratio: $!}; my $file_width = $image->width(); my $file_height = $image->height(); my $file_ratio = sprintf("%.2f", $file_width / $file_height); ### get exif data require Image::ExifTool; my $exif_tool = new Image::ExifTool; my $exif_info = $exif_tool->ImageInfo(qq{./pictures/$gal_securestring/org-$file_hash.jpg}) or print qq{Cant read exifdata: $!}; ### data saved in: $$info{'DateTimeOriginal'} ### clean name: use HTML::Entities; my $file_name = encode_entities($file); ### insert in mysql db require MySQL; new MySQL->insert({ values => { gid => $self->get_id(), uid => $self->get_session()->param('u_id'), name => $file_name, hash => $file_hash, ratio => $file_ratio, exif => $$exif_info{'DateTimeOriginal'}, created => 'NOW()', clicks => 0 }, table => 'pictures' }); ### send success my $json_to_parse = { result => 'success' }; require JSON; my $output_as_json = new JSON->pretty->encode($json_to_parse); require Parser; new Parser({ data => $output_as_json, outputtype => 'js', })->output(); } Viele Grüße :)
|