[Mapbender-commits] r9914 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Jun 14 01:39:24 PDT 2018
Author: armin11
Date: 2018-06-14 01:39:24 -0700 (Thu, 14 Jun 2018)
New Revision: 9914
Modified:
trunk/mapbender/http/php/mb_metadata_uploadLayerPreview.php
Log:
Fix for handling of preview image - possibility to alter and delete previews - thanx to fa benndorf
Modified: trunk/mapbender/http/php/mb_metadata_uploadLayerPreview.php
===================================================================
--- trunk/mapbender/http/php/mb_metadata_uploadLayerPreview.php 2018-06-14 08:38:29 UTC (rev 9913)
+++ trunk/mapbender/http/php/mb_metadata_uploadLayerPreview.php 2018-06-14 08:39:24 UTC (rev 9914)
@@ -14,8 +14,7 @@
require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
$user_id = Mapbender::session()->get("mb_user_id");
-$data = $_POST;
-$source_id = $data['source_id'];
+$source_id = $_POST['source_id'];
//set variables
$width;
$height;
@@ -28,119 +27,124 @@
// get the extension of the file
$ext = $info['extension'];
// set the new fileName
-if ($service == 'admin_wmc_metadata') {
+$type = $_POST['type'];
+
+if ($type == 'wmc') {
$new_name = $source_id."_wmc_preview.jpg";//.$ext;
}
else {
-
$new_name = $source_id."_layer_map_preview.jpg";//.$ext;
+}
-}
-// get the ímage
-$image = $_FILES['image']['tmp_name'];
-//resize the image to 200px * 200px
$new_image = dirname(__FILE__)."/../geoportal/preview/".$new_name;
-// get image size
-$size = Getimagesize($image);
-$images_orig;
-//create an gd-image-object from the source file
-switch ($ext) {
- case 'jpg':
- $images_orig = ImageCreateFromJPEG($image);
- break;
+if ($_POST["upload_action"] === "upload") {
+ // get the ímage
+ $image = $_FILES['image']['tmp_name'];
+ //resize the image to 200px * 200px
+ // get image size
+ $size = Getimagesize($image);
+ $images_orig;
+ //create an gd-image-object from the source file
+ switch ($ext) {
+ case 'jpg':
- case 'jpeg':
+ $images_orig = ImageCreateFromJPEG($image);
+ break;
- $images_orig = ImageCreateFromJPEG($image);
- break;
+ case 'jpeg':
- case 'png':
+ $images_orig = ImageCreateFromJPEG($image);
+ break;
- $images_orig = ImageCreateFrompng($image);
- break;
+ case 'png':
- case 'gif':
+ $images_orig = ImageCreateFrompng($image);
+ break;
- $images_orig = ImageCreateFromgif($image);
- break;
+ case 'gif':
- default:
+ $images_orig = ImageCreateFromgif($image);
+ break;
- return;
- break;
-}
-//if width and height are to big
-if ($size[0] >= 200 || $size[1] >= 200) {
- // width of the origin image
- $photoW = ImagesX($images_orig);
- // height of the origin image
- $photoH = ImagesY($images_orig);
- // create new image with the calculated size
- $images_target = ImageCreateTrueColor(200, 200);
- //fill the new image with transparency background
- $color = imagecolorallocatealpha($images_target, 255, 255, 255, 0); //fill white background
- imagefill($images_target, 0, 0, $color);
- imagealphablending( $images_target, false );
- imagesavealpha($images_target, true);
- //set the new image width and height
- if ($size[0] > $size[1] || $size[0] == $size[1]) {
+ default:
- $width = 200;
- $height = round($width*$size[1]/$size[0]);
+ return;
+ break;
+ }
+ //if width and height are to big
+ if ($size[0] >= 200 || $size[1] >= 200) {
+ // width of the origin image
+ $photoW = ImagesX($images_orig);
+ // height of the origin image
+ $photoH = ImagesY($images_orig);
+ // create new image with the calculated size
+ $images_target = ImageCreateTrueColor(200, 200);
+ //fill the new image with transparency background
+ $color = imagecolorallocatealpha($images_target, 255, 255, 255, 0); //fill white background
+ imagefill($images_target, 0, 0, $color);
+ imagealphablending( $images_target, false );
+ imagesavealpha($images_target, true);
+ //set the new image width and height
+ if ($size[0] > $size[1] || $size[0] == $size[1]) {
+
+ $width = 200;
+ $height = round($width*$size[1]/$size[0]);
+ // calculate the height of the src_image in the target_image
+ $startHeight = round((200-$height)/2);
+ // resize the image:
+ ImageCopyResampled($images_target, $images_orig, 0, $startHeight, 0, 0, $width, $height, $photoW, $photoH);
+
+ }else{
+
+ $height = 200;
+ $width = round($height*$size[0]/$size[1]);
+ $startWidth = round((200-$width)/2);
+ ImageCopyResampled($images_target, $images_orig, $startWidth, 0, 0, 0, $width, $height, $photoW, $photoH);
+ }
+ // move File to the new target directory --> always save as png
+ imagejpeg($images_target,$new_image);
+ // free space
+ ImageDestroy($images_orig);
+ ImageDestroy($images_target);
+ echo "<img src=\""."../geoportal/preview/".$new_name."\">";
+ } // if image-width and height are to small
+ else if($size[0] < 200 && $size[1] < 200){
+ //set the new image width
+ $width = $size[0];
+ // scale the height
+ $height = $size[1];
+ // width of the origin image
+ $photoW = ImagesX($images_orig);
+ // height of the origin image
+ $photoH = ImagesY($images_orig);
+ // create new image with the calculated size
+ $images_target = ImageCreateTrueColor(200, 200);
+ //fill the new image with transparency background
+ $color = imagecolorallocatealpha($images_target, 255, 255, 255, 0); //fill white background
+ imagefill($images_target, 0, 0, $color);
+ imagealphablending( $images_target, false );
+ imagesavealpha($images_target, true);
// calculate the height of the src_image in the target_image
$startHeight = round((200-$height)/2);
- // resize the image:
- ImageCopyResampled($images_target, $images_orig, 0, $startHeight, 0, 0, $width, $height, $photoW, $photoH);
-
- }else{
-
- $height = 200;
- $width = round($height*$size[0]/$size[1]);
$startWidth = round((200-$width)/2);
- ImageCopyResampled($images_target, $images_orig, $startWidth, 0, 0, 0, $width, $height, $photoW, $photoH);
+ // resize the image
+ ImageCopyResampled($images_target, $images_orig, $startWidth, $startHeight, 0, 0, $width, $height, $photoW, $photoH);
+ // move File to the new target directory --> always save as png
+ imagejpeg($images_target,$new_image);
+ // free space
+ ImageDestroy($images_orig);
+ ImageDestroy($images_target);
+ echo "<img src=\""."../geoportal/preview/".$new_name."\">";
}
- // set new target dir
- $target = dirname(__FILE__).'/../tmp/'.$new_name;
- // move File to the new target directory --> always save as png
- imagejpeg($images_target,$new_image);
- // free space
- ImageDestroy($images_orig);
- ImageDestroy($images_target);
- return;
-} // if image-width and height are to small
-else if($size[0] < 200 && $size[1] < 200){
- //set the new image width
- $width = $size[0];
- // scale the height
- $height = $size[1];
- // width of the origin image
- $photoW = ImagesX($images_orig);
- // height of the origin image
- $photoH = ImagesY($images_orig);
- // create new image with the calculated size
- $images_target = ImageCreateTrueColor(200, 200);
- //fill the new image with transparency background
- $color = imagecolorallocatealpha($images_target, 255, 255, 255, 0); //fill white background
- imagefill($images_target, 0, 0, $color);
- imagealphablending( $images_target, false );
- imagesavealpha($images_target, true);
- // calculate the height of the src_image in the target_image
- $startHeight = round((200-$height)/2);
- $startWidth = round((200-$width)/2);
- // resize the image
- ImageCopyResampled($images_target, $images_orig, $startWidth, $startHeight, 0, 0, $width, $height, $photoW, $photoH);
- // set new target dir
- $target = dirname(__FILE__).'/../tmp/'.$new_name;
- // move File to the new target directory --> always save as png
- imagejpeg($images_target,$new_image);
- // free space
- ImageDestroy($images_orig);
- ImageDestroy($images_target);
- return;
+} else if ($_POST["upload_action"] === "delete") {
+ unlink($new_image);
+ echo "<img class=\"defaultPreview\" src=\""."../geoportal/preview/keinevorschau.jpg\">";
+} else if ($_POST["upload_action"] === "getImage") {
+ if(!file_exists($new_image)) {
+ echo "<img class=\"defaultPreview\" src=\""."../geoportal/preview/keinevorschau.jpg\">";
+ } else {
+ echo "<img src=\""."../geoportal/preview/".$new_name."\">";
+ }
}
-
-
-
-
More information about the Mapbender_commits
mailing list