[Mapbender-commits] r1125 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Feb 13 21:37:03 EST 2007
Author: marcjansen
Date: 2007-02-13 21:37:01 -0500 (Tue, 13 Feb 2007)
New Revision: 1125
Modified:
trunk/mapbender/http/classes/class_weldLegend2PNG.php
Log:
Added documentation,
added imagedestroy for temporary images
Modified: trunk/mapbender/http/classes/class_weldLegend2PNG.php
===================================================================
--- trunk/mapbender/http/classes/class_weldLegend2PNG.php 2007-02-13 16:38:47 UTC (rev 1124)
+++ trunk/mapbender/http/classes/class_weldLegend2PNG.php 2007-02-14 02:37:01 UTC (rev 1125)
@@ -1,7 +1,7 @@
<?php
# $Id$
# http://www.mapbender.org/index.php/class_weldLegend2PNG.php
-# Copyright (C) 2002 CCGIS
+# Copyright (C) 2002 CCGIS
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,49 +17,83 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-/*
-* class_weldMaps2PNG
-* @version 1.0.0
-* get/post '___' separated maprequests
-*
-**/
+
require_once(dirname(__FILE__)."/class_stripRequest.php");
require_once(dirname(__FILE__)."/class_mb_exception.php");
+
+/**
+ * Class used to weld different images (coming from various maprequests) together.
+ * These maprequests are supposed to be passed to the constructor as '___'-seperated urls.
+ *
+ * @version 1.0.0
+ * @uses stripRequest
+ */
class weldMaps2PNG{
-
- function weldMaps2PNG($urls,$filename){
+ /**
+ * Constructor, assumes you pass over two parameters: the first is a string with
+ * different maprequests, each seperated by three underscores (___).
+ *
+ * Iteratively calls a method to generate temporary images which are welded together at once.
+ * The generated image is saved to the filesystem under the name
+ * passed over as second parameter to the constructor.
+ *
+ * @param <string> the maprequests seperated by three underscores
+ *
+ */
+ function weldMaps2PNG($urls, $filename){
if(!$urls || $urls == ""){
$e = new mb_exception("weldMaps2PNG: no maprequests delivered");
}
+ // getting the array of urls
$url = explode("___", $urls);
+ // make url parameters accessible
$obj1 = new stripRequest($url[0]);
$width = $obj1->get("width");
$height = $obj1->get("height");
-
+ // create output image
$image = imagecreatetruecolor($width, $height);
- $white = ImageColorAllocate($image,255,255,255);
- ImageFilledRectangle($image,0,0,$width,$height,$white);
+ // assign a white background color
+ $white = ImageColorAllocate($image,255,255,255);
+ ImageFilledRectangle($image,0,0,$width,$height,$white);
+ // iterate over each request
for($i=0; $i<count($url); $i++){
$obj = new stripRequest($url[$i]);
- #$url[$i] = $obj->setPNG();
+// $url[$i] = $obj->setPNG();
$url[$i] = $obj->encodeGET();
+ // get temporary image for this URL
$img = $this->loadpng($url[$i]);
if($img != false){
+ // copy temporary image over already assigned images
imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+ imagedestroy($img);
}
else{
$e = new mb_exception("weldMaps2PNG: unable to copy image: " . $url[$i]);
}
}
+ // output the image to the filesystem
+ /**
+ * @todo different outputs?
+ */
imagepng($image,$filename);
- imagedestroy($image);
-
+ imagedestroy($image);
}
+
+ /**
+ * Helper function to generate temporary images for each URL
+ *
+ * @param <string> a single URL which represents a maprequest
+ */
function loadpng ($imgurl) {
-
$obj = new stripRequest($imgurl);
$f = $obj->get("format");
+ /**
+ * react on format
+ * @todo create switch?
+ * @todo handle as reg-exp?
+ * @todo instanciate $im as false or null?
+ */
if(strtolower($f) == 'image/png' || strtolower($f) == 'png'){
$im = @ImageCreateFromPNG($imgurl);
}
@@ -72,9 +106,10 @@
if(!$im){
$im = false;
$e = new mb_exception("weldMaps2PNG: unable to load image: ".$imgurl);
- }
+ }
+ // return the temporary image
return $im;
}
-}
+} // eof class weldMaps2PNG
?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list