CAM-PDF

 view release on metacpan or  search on metacpan

bin/crunchjpgs.pl  view on Meta::CPAN


            my $jpg = CAM::PDF->new($content) || die "$CAM::PDF::errstr\n";
            my $jpgim   = $jpg->getObjValue(8);
            my $jpgsize = $jpg->getValue($jpgim->{Length});

            if ($jpgsize < $oldsize) {
              $doc->replaceObject($objnum, $jpg, 8, 1);

              $newtotsize += $jpgsize;

              my $percent = sprintf '%.1f', 100 * ($oldsize - $jpgsize) / $oldsize;
              _inform("\tcompressed $oldsize -> $jpgsize ($percent%)", $opts{verbose});
            $doneobjs{$objnum} = 1;
            $rimages++;
            } else {
              _inform("\tskipped $oldsize -> $jpgsize", $opts{verbose});
            }

         }
      }
   }
}

_inform("Crunched $rimages of $nimages images", $opts{verbose});
$doc->cleanoutput($outfile);

my $newcontentsize = $doc->{contentlength};

if ($opts{verbose})
{
   my $contentpercent = sprintf '%.1f', $oldcontentsize ? 100 * ($oldcontentsize - $newcontentsize) / $oldcontentsize : 0;
   my $totpercent = sprintf '%.1f', $oldtotsize ? 100 * ($oldtotsize - $newtotsize) / $oldtotsize : 0;
   _inform('Compression summary:', 1);
   _inform("  Document: $oldcontentsize -> $newcontentsize ($contentpercent%)", 1);
   _inform("  Images: $oldtotsize -> $newtotsize ($totpercent%)", 1);
}

sub _isjpg
{
   my $im = shift;
   return if (!$im->{Filter});

   my $f = $im->{Filter};
   my @names = $f->{type} eq 'array' ? @{$f->{value}} : $f;
   for my $e (@names)



( run in 0.447 second using v1.01-cache-2.11-cpan-709fd43a63f )