optimization of background image creation

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@2793 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2013-02-24 08:47:30 +00:00
parent 6e509ba68f
commit b014230a71

View File

@ -368,8 +368,9 @@ RSS_returnJPEG($) {
#
# create the image
#
my $S= GD::Image->newTrueColor($width,$height);
$S->colorAllocate(0,0,0); # black is the background
my $S;
# my $S= GD::Image->newTrueColor($width,$height);
# $S->colorAllocate(0,0,0); # black is the background
# wrap to make problems with GD non-lethal
@ -410,6 +411,8 @@ RSS_returnJPEG($) {
my $bgfile= $bgdir . "/" . $bgfiles[$bgnr];
my $bg= newFromJpeg GD::Image($bgfile);
my ($bgwidth,$bgheight)= $bg->getBounds();
if($bgwidth != $width or $bgheight != $height) {
# we need to resize
my ($w,$h);
my ($u,$v)= ($bgwidth/$width, $bgheight/$height);
if($u>$v) {
@ -419,7 +422,18 @@ RSS_returnJPEG($) {
$h= $height;
$w= $bgwidth/$v;
}
# create empty image
$S= GD::Image->newTrueColor($width,$height);
$S->colorAllocate(0,0,0); # black is the background
$S->copyResized($bg,($width-$w)/2,($height-$h)/2,0,0,$w,$h,$bgwidth,$bgheight);
} else {
# size is as required, we take the original
$S= $bg;
}
} else {
# no background, we create an empty background
$S= GD::Image->newTrueColor($width,$height);
$S->colorAllocate(0,0,0); # black is the background
}
SKIPBG: