[Mapbender-commits] r7780 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Apr 19 01:48:35 EDT 2011
Author: armin11
Date: 2011-04-18 22:48:35 -0700 (Mon, 18 Apr 2011)
New Revision: 7780
Modified:
trunk/mapbender/http/classes/class_SaveLegend.php
Log:
Bugfix for saving legends for the print module. Sometimes it is not possible to get the size of the image by url - therefor the image must be stored as a file before extracting the size!
Modified: trunk/mapbender/http/classes/class_SaveLegend.php
===================================================================
--- trunk/mapbender/http/classes/class_SaveLegend.php 2011-04-18 16:00:33 UTC (rev 7779)
+++ trunk/mapbender/http/classes/class_SaveLegend.php 2011-04-19 05:48:35 UTC (rev 7780)
@@ -33,27 +33,40 @@
if(!$url || $url == ""){
$e = new mb_exception("SaveLegend: no legendurl delivered");
}
- #$obj1 = new stripRequest($url);
- $size = getimagesize($url);
+ $x = new connector($url);
+ //save file in tmp folder to extract right size - sometimes the size could not be detected by url!
+ if($legendFileHandle = fopen($legend_filename, "w")){
+ fwrite($legendFileHandle,$x->file);
+ fclose($legendFileHandle);
+ $e = new mb_notice("SaveLegend: new legend file created: ".$legend_filename);
+ } else {
+ $e = new mb_exception("SaveLegend: legend file ".$legend_filename." could not be created!");
+ }
+ //get size of image
+ $size = getimagesize($legend_filename);
$width = $size[0];
$height = $size[1];
-
$image = imagecreatetruecolor($width, $height);
$white = ImageColorAllocate($image,255,255,255);
- ImageFilledRectangle($image,0,0,$width,$height,$white);
-
- $img = $this->loadpng($url);
- if($img != false){
- imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
- }else{
- $e = new mb_exception("SaveLegend: unable to load image: " . $url);
- }
+ ImageFilledRectangle($image,0,0,$width,$height,$white);
+ //load image from url to create new image
+ $img = $this->loadpng($url);
+ if($img != false){
+ imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+ }else{
+ $e = new mb_exception("SaveLegend: unable to load image: " . $url);
+ }
+ //save image to same filename as before
imagepng($image,$legend_filename);
imagedestroy($img);
}
function loadpng ($imgurl) {
$x = new connector($imgurl);
- $im = @imagecreatefromstring($x->file);
+ try {
+ $im = imagecreatefromstring($x->file);
+ }catch(Exception $E){
+ $e = new mb_exception("Can't read image from string: ".$E->getmessage);
+ }
if(!$im){
$im = false;
$e = new mb_exception("SaveLegend: unable to load image: ".$imgurl);
More information about the Mapbender_commits
mailing list