[Mapbender-commits] r2145 - branches/2.4.5/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Feb 27 07:47:00 EST 2008
Author: astrid_emde
Date: 2008-02-27 07:47:00 -0500 (Wed, 27 Feb 2008)
New Revision: 2145
Added:
branches/2.4.5/http/classes/class_weldMaps2Image.php
Log:
new class for Export Image
http://www.mapbender.org/ExportMapimage
Added: branches/2.4.5/http/classes/class_weldMaps2Image.php
===================================================================
--- branches/2.4.5/http/classes/class_weldMaps2Image.php (rev 0)
+++ branches/2.4.5/http/classes/class_weldMaps2Image.php 2008-02-27 12:47:00 UTC (rev 2145)
@@ -0,0 +1,166 @@
+<?php
+# $Id$
+# http://www.mapbender.org/
+# 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/class_stripRequest.php");
+require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+
+ /*
+ * Class generats Images (jpegs/pngs/geotiff)
+ * of Image-URL-Array
+ * For geotiff export gdal is necessary
+ *
+ */
+ class weldMaps2Image{
+
+ var $urls = array();
+ var $filename;
+
+ function weldMaps2Image($urls, $array_file){
+ $this->urls = $urls;
+ $this->array_file = $array_file;
+ }
+
+
+ function getImage($imageTyp_imp, $outputKind=''){
+
+ $imageTyp="";
+ $imageTyp=$imageTyp_imp;
+
+ if($imageTyp=='jpg'){
+ $imageTyp='jpeg';
+ }
+
+ if(!$this->urls || $this->urls == ""){
+ $e = new mb_exception("weldMaps2Image: no maprequests delivered");
+ }
+ $obj1 = new stripRequest($this->urls[0]);
+ $width = $obj1->get("width");
+ $height = $obj1->get("height");
+ $wms_srs = $obj1->get("srs");
+ $wms_bbox = $obj1->get("bbox");
+ $wms_format = $obj1->getFormat();
+
+ $image = imagecreatetruecolor($width, $height );
+ $white = ImageColorAllocate($image,255,255,255);
+ ImageFilledRectangle($image,0,0,$width,$height,$white);
+
+ for($i=0; $i<count($this->urls); $i++){
+ $obj = new stripRequest($this->urls[$i]);
+ if($imageTyp=='geotiff'){
+ $this->urls[$i] = $obj->setFormat($wms_format);
+ } else {
+ $this->urls[$i] = $obj->setFormat($imageTyp);
+ }
+
+ $this->urls[$i] = $obj->encodeGET();
+ $img = $this->loadImage($this->urls[$i]);
+ if($img != false){
+ imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+ }
+ else{
+ $e = new mb_exception("weldMaps2Image: unable to load image: " . $this->urls[$i]);
+ }
+ }
+
+ $filename = $this->array_file['dir']."/";
+ $timestamp = time();
+ $filenameOnly =$this->array_file['filename'].md5($timestamp);
+
+ if($imageTyp=='png'){
+
+ $filenameOnly .= '.png';
+ $filename .= $filenameOnly;
+
+ imagepng($image, $filename);
+
+ echo $this->downloadLink("../php/download.php?download=".$filenameOnly);
+
+ } else if($imageTyp=='jpeg'){
+
+ $filenameOnly .= '.jpeg';
+ $filename .= $filenameOnly;
+ imagejpeg($image, $filename);
+
+ echo $this->downloadLink("../php/download.php?download=".$filenameOnly);
+
+ } else if($imageTyp=='geotiff'){
+
+ $filenameOnly .= '.'.$wms_format;
+ $filename .= $filenameOnly;
+
+ if ($wms_format=='png'){
+ imagepng($image, $filename);
+ } else if ($wms_format=='jpeg'){
+ imagejpeg($image, $filename);
+ } else {
+ $e = new mb_exception("weldMaps2Image: unable to generate temp-Image for getiff: " . $filename);
+ }
+
+ // gdal_translate...
+ $wms_bbox = str_replace(',', ' ', $wms_bbox);
+ $filename_tif = str_replace($wms_format, 'tif', $filenameOnly);
+
+ $tmp_dir = $this->array_file['dir'];
+ $cmd = "gdal_translate -a_srs ".$wms_srs." -a_ullr ".$wms_bbox." ".$tmp_dir.$filenameOnly." ".$tmp_dir.$filename_tif;
+// echo "cmd: <br>".$cmd."<br>";
+ exec($cmd);
+
+
+ echo "<br>";
+ echo $this->downloadLink("../php/download.php?download=".$filename_tif);
+
+ }else {
+
+ }
+
+
+ }
+
+ function loadImage ($imgurl) {
+
+ $x = new connector($imgurl);
+ $im = @imagecreatefromstring($x->file);
+ if(!$im){
+ $im = false;
+ $e = new mb_exception("weldMaps2Image: unable to load image: ".$imgurl);
+ }
+ return $im;
+
+ }
+
+ function downloadLink($link){
+ return "<a href=".$link.">Image Download</a>";
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+?>
Property changes on: branches/2.4.5/http/classes/class_weldMaps2Image.php
___________________________________________________________________
Name: svn:keywords
+ HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
More information about the Mapbender_commits
mailing list