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