Thread [Image-Magick] BlobToImage (17 answers)
Opened by Kean at 2013-01-11 12:04

GwenDragon
 2013-01-11 16:36
#164903 #164903
User since
2005-01-17
14748 Artikel
Admin1
[Homepage]
user image
Mein Testcase klappt so:
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
#!/usr/bin/perl

use 5.008;
use strict;
use warnings;

use Image::Magick;
use MIME::Base64;

use DBI;

#data:image/gif;base64,R0lGODlhJAAlAPcAAAAAAAAAMwAAZgAAmQAAzAAA/wArAAArMwArZgArmQArzAAr/wBVAABVMwBVZgBVmQBVzABV/wCAAACAMwCAZgCAmQCAzACA/wCqAACqMwCqZgCqmQCqzACq/wDVAADVMwDVZgDVmQDVzADV/wD/AAD/MwD/ZgD/mQD/zAD//zMAADMAMzMAZjMAmTMAzDMA/zMrADMrMzMrZjMrmTMrzDMr/zNVADNVMzNVZjNVmTNVzDNV/zOAADOAMzOAZjOAmTOAzDOA/zOqADOqMzOqZjOqmTOqzDOq/zPVADPVMzPVZjPVmTPVzDPV/zP/ADP/MzP/ZjP/mTP/zDP//2YAAGYAM2YAZmYAmWYAzGYA/2YrAGYrM2YrZmYrmWYrzGYr/2ZVAGZVM2ZVZmZVmWZVzGZV/2aAAGaAM2aAZmaAmWaAzGaA/2aqAGaqM2aqZmaqmWaqzGaq/2bVAGbVM2bVZmbVmWbVzGbV/2b/AGb/M2b/Zmb/mWb/zGb//5kAAJkAM5kAZpkAmZkAzJkA/5krAJkrM5krZpkrmZkrzJkr/5lVAJlVM5lVZplVmZlVzJlV/5mAAJmAM5mAZpmAmZmAzJmA/5mqAJmqM5mqZpmqmZmqzJmq/5nVAJnVM5nVZpnVmZnVzJnV/5n/AJn/M5n/Zpn/mZn/zJn//8wAAMwAM8wAZswAmcwAzMwA/8wrAMwrM8wrZswrmcwrzMwr/8xVAMxVM8xVZsxVmcxVzMxV/8yAAMyAM8yAZ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KjPxoATFy9zIuBb84IzZerxfkJjFjU7xhxA4+wmYmG0GJqjgggw26OCDCgYEADs='
};
my $blob = $ref->{'Grafik'};
# Fülle BLOB mit binären Daten
$blob = MIME::Base64::decode_base64($blob); 

my $dbh = DBI->connect("dbi:mysql:test", "test", "test") or die $DBI::errstr;

# Tabelle erzeugen und BLOB mit binären Daten beschicken
$dbh->do('DROP TABLE test');
$dbh->do('CREATE TABLE test (id INT, b BLOB)');
$dbh->do('INSERT INTO test VALUES(1, ?)', undef, $blob);

# Daten holen
my $hash_ref = $dbh->selectrow_hashref('SELECT * FROM test WHERE id = 1');

if ($hash_ref) {
        $blob = $hash_ref->{'b'} or die "BLOB leer!?";
        
        ### testmode zur Ausgabe auf Webserver
        #binmode (STDOUT);
        #print 'Content-Type: image/gif', "\n\n", $blob;

        my $image = Image::Magick->new();
        $image->BlobToImage($blob);
        $image->Write('/tmp/test.png'); 
}


Schau dir mal an was du gemachst hast und was ich. ;)

View full thread [Image-Magick] BlobToImage