View Single Post
Old 04-17-2008, 10:24 AM   #16
nrapallo
GuteBook/Mobi2IMP Creator
nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.nrapallo ought to be getting tired of karma fortunes by now.
 
nrapallo's Avatar
 
Posts: 2,958
Karma: 2530691
Join Date: Dec 2007
Location: Toronto, Canada
Device: REB1200 EBW1150 Device: T1 NSTG iLiad_v2 NC Device: Asus_TF Next1 WPDN
Quote:
Originally Posted by tompe View Post
The thing is that nearly all files with large images generated by MobiPerl has these problems but files generated with MobiPocket Creator with the same images generally do not have the problem.
tompe:

I had a similar problem when writing mobi2imp.pl where the resulting images would fail to show up in the ereader. What I did was, using GD, just copyResized the images but not actually resize them. What this did was rewrite the images using the GD library and those images would then load and show up properly. Maybe Mobipocket Creator does something similar, internally.

Sample code (you originally wrote this!) fixing this issue in mobi2perl.pl:
Code:
sub fix_image_tags {
    my $tree = shift;
    my @imgel = $tree->find ("img");
    foreach my $img (@imgel) {
	my $recindex = $img->attr ("recindex");
	my $ind = int ($recindex);
	my $filename = $image_index_to_filename{$ind};
###################################################################
#For .IMP start - just rewrite .jpg/.png/.gif image files (fixes non-stnd pics)
#
 if (defined $opt_verbose || defined $opt_debug){ print "FIXED IMAGE/TAGS: $recindex - $ind - $filename\n"; }
 
 my $imagefile = "$explodedir/$filename";
 my $supportedimage = 0;
 #my ($body,$path,$ext) = fileparse("$imagefile",'\.\w+');
 
 my $im = $imagefile;
 $im =~ /\.jpe?g$/i and $im = GD::Image->newFromJpeg($imagefile,1) and $supportedimage = 1;
 $im =~ /\.gif$/i   and $im = GD::Image->newFromGif($imagefile) and $supportedimage = 1  and $im->transparent(-1);  #use only non-transparent .gifs;
 $im =~ /\.png$/i   and $im = GD::Image->newFromPng($imagefile) and $supportedimage = 1;
 #$im =~ /\.bmp$/i  and next; # not yet implemented in GD, but hopefully not needed here!
 
 if ($supportedimage) {
     my ($width, $height) = $im->getBounds();
 
     my $target_im = new GD::Image($width,$height,1);
     $target_im->copyResized($im,0,0,0,0,$width,$height,$width,$height);
     
     open(IMAGE, "> $imagefile");
     binmode(IMAGE);
     if ($imagefile =~ /\.jpe?g$/i){
         print IMAGE $target_im->jpeg(85);
     } elsif ($imagefile =~ /\.gif$/i) {
         print IMAGE $target_im->gif();
     } elsif ($imagefile =~ /\.png$/i) {
         print IMAGE $target_im->png();
     } #elsif ($imagefile =~ /\.bmp$/i) {
       #  print IMAGE $target_im->bmp();
       #}
     close(IMAGE);
 }
#
#For .IMP end
###################################################################
	$img->attr ("recindex", undef);
	$img->attr ("src", $filename);
    }
}
Just a thought!
nrapallo is offline   Reply With Quote