wiki:SWIGMapScriptOpacity

Using setOpacity() method for SWIG MapScript

<?php

// define variables
define( "MAPFILE", "C:/ms4w/apps/phpmapscriptng-swig/output.map" );

// required SWIG include (contains constants for PHP7)
include("C:/ms4w/apps/phpmapscriptng-swig/include/mapscript.php");

// open map
$oMap = new mapObj(MAPFILE);

//force all errors to display
//  comment out the next 2 lines, useful on servers not displaying errors
ini_set('display_errors','On');
error_reporting(E_ALL);

// set image size
$oMap->setsize(400, 300);

// set image format
$oMap->selectoutputformat("png");


// get layer
$oPolyLayer = $oMap->getLayerByName('prov_bound');

//***********************************************************************************************
// set opacity on the layer
//***********************************************************************************************
// call setOpacity() (which actually creates a new COMPOSITE object)
$oPolyLayer->setOpacity(40);

// draw map
$oImage = $oMap->draw();

// save image file
$file = $oImage->save("C:/ms4w/apps/phpmapscriptng-swig/ttt.png",$oMap);

//***********************************************************************************************
// save mapfile to new file, to see your new COMPOSITE object inside the layer
//***********************************************************************************************
$oMap->save("C:/ms4w/apps/phpmapscriptng-swig/output2.map");

// set header
header("Content-type: image/gif");

// read image to output buffer
readfile("C:/ms4w/apps/phpmapscriptng-swig/ttt.png");

?>
Last modified 2 months ago Last modified on May 16, 2019, 9:13:07 AM