Enhancement: drawFromPictureResized

8 views
Skip to first unread message

RepThe415

unread,
Sep 30, 2009, 4:45:00 AM9/30/09
to mtChart Discussions
Got an enhancement for mtChart.

If you need to draw an image to the Graph and would like to resize it
right use this function drawFromPictureResized. You can basically pass
jpg, png and gif images. PHP should autodetect on loading the image to
the image object.

/**
* Load Image from any image file and resize it.
* */
public function drawFromPictureResized($FileName, $X, $Y,
$W=false, $H=false) {
if (file_exists($FileName)) {
$Infos = getimagesize($FileName);
$Width = $Infos[0];
$Height = $Infos[1];
$NewWidth = ($W) ? $W : $Width;
$NewHeight = ($H) ? $H : $Height;

$Raster = imagecreatefromstring(file_get_contents
($FileName));
imagecopyresampled($this->Picture, $Raster, $X, $Y, 0, 0,
$NewWidth, $NewHeight, $Width, $Height);
imagedestroy($Raster);
return true;
}
}

Maybe you can add it as an "official" mtChart function in the next
release?

Thank You!!!

p.s. oh and maybe you should think about adding a counter for the
computescale while to break the while if the loop is taking too long.
Crashed my system several times :(
Reply all
Reply to author
Forward
0 new messages