hotti: Beispiel Inline-Grafik

Beitrag lesen

hi again,

Beispiel Perl-CGI

Hotti

PS: Das Script ist recht einfach anzupassen. Getestet mit FF und IE(neuerer Bauart)

#~~~~~~~~~~~~~~~~~~~~ Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  
#!/usr/bin/perl  
  
use strict;  
use warnings;  
use myConfig qw($cfg);  
use IO::File;  
use MIME::Base64 qw(encode_base64);  
  
print "Content-Type:text/html; charset=UTF-8\n\n";  
print "<h1>Image Inline</h2>";  
  
  
if(-f "$cfg->{path}->{filedir}/red.gif"){  
	my $fh = new IO::File "$cfg->{path}->{filedir}/red.gif", O_RDONLY|O_BINARY;  
	my $binary = undef;  
	read($fh, $binary, -s _); # Lese BinärDatei  
	  
	# jetzt kann der Inhalt ausgegeben werden  
	# zunächst die Inline-Grafik  
	my $inline = "data:image/gif;base64,".encode_base64($binary);  
	print qq(  
		<p>  
			Unten sollte eine Grafik zu sehen sein:  
		</p>  
		  
		<p>  
			<img src="$inline">  
		</p>  
	  
	);  
  
}  
else{  
	print "<p>Image nicht gefunden</p>";  
}