#!/usr/local/bin/perl -w use strict; use warnings; use Image::Magick; sub slurp { my ($path, $ref) = @_; my $fh; unless(open $fh, "<", $path) { die "Fehler beim Öffnen von '$path': $^E"; } binmode $fh; local $/; ${$ref} = <$fh>; close $fh; } # main my $pdffile = "test.pdf"; my $string; slurp($pdffile, \$string); my $im = Image::Magick->new; my $err; # PDF einlesen # PostScript-Auflösung etc. vorher (sic!) setzen $im->Set( density => 144, depth => 8, units => 'PixelsPerInch', colorspace => 'RGB', ); # PDF einlesen (aus Datei) #$err = $im->Read($pdffile); # PDF einlesen (aus String) $err = $im->BlobToImage($string); # Thumbnail z.B. JPEG erstellen my $tn = $im->Clone; # auf die gewünschte Größe herunterrechnen $err = $tn->Resize( geometry => '130x130', ); # Breite und Höhe ermitteln my $width = $tn->Get('columns'); my $height = $tn->Get('height'); print "width $width; height $height\n"; $tn->Set( quality => 75, magick => 'JPG', ); my $jpgfile = "test.jpg"; # JPEG schreiben $tn->Write($jpgfile); # JPEG als String my $blob = $tn->ImageToBlob;