Ticket #110 (new enhancement)

Opened 7 years ago

Last modified 4 years ago

[PHP MapScript] Link between PHP/MapScript and PHP/PDF and PHP/GD

Reported by: dmorissette Assigned to: dmorissette
Priority: highest Milestone: FUTURE
Component: MapScript-PHP Version: 4.1
Severity: minor Keywords:
Cc: pspencer@dmsolutions.ca, huub@geodan.nl

Description

See the thread "PFD Output: How?" (2002-02-16) on the MapServer-users list for 
the full story...

Paul Ramsey wrote:
> 
> (b) In terms of implementation of PDF support in PHP/Mapscript, my
> recommendation would be this:
> 
> (1) that the existing PDF support in PHP be examined, and depended on,
> so that to create PDF version of a map you would first create a standard
> PHP PDF object, then pass that object to the mapscript PDF writing
> function.

Paul,

Taking advantage of the existing PDF module in PHP would be great, and we've 
been thinking about doing the same with GD to use the PHP GD module to add 
annotations on top of a MapScript imageObj.

The problem is that the PHP GD and PDF modules are separate modules and we don't 
have any control on them, each module uses its own data structures internally 
and I never saw anything in PHP that allowed modules to share resources even if 
they share the same C data structures at the lower level (a PDF or GD handle is 
a resource in PHP).

This would be a nice thing to research (when time permits), but I'm suspecting 
that we would have to build some kind of bridge to export an imageObj into a PHP 
GD image object and vice-versa... and that we would have to maintain this bridge 
for every release of PHP... that's the main reason why we didn't do it yet: it's 
already hard enough to maintain the PHP module compatible between PHP versions 
without this kind of dependencies with external modules.

Change History

02/27/02 12:41:24 changed by cabral@yadata.net

Two things:

1) Jamie Wall, responsible by MapServer's PDF functions, has - per request - 
implemented two new functions in mappdf.c, which will soon be available to CVS:
- PDF *msDrawMapPageSizePositionPDF(...); and
- PDF *msDrawMapSizePositionPDF(...)
(check source files for arguments).

So, if everything goes well in mapscript, one would simply do:
$pdf = pdf_new();
(...)
$map->drawMapSizePositionPDF( $pdf, ... );

2) How can we make $pdf be the SAME one from PDFlib? I'm sure folks at DM 
Solutions know the drill, but here's my humble suggestion -- correct if I'm 
wrong.
2.1) Make "le_pdf" in php/ext/pdf.c public to mapscript. This can be 
accomplished through public function phpi_get_le_pdf() defined in php_pdf.h and 
pdf.c (see in php/ext/gd similar function phpi_get_le_gd). NOTE: this will have 
to be commited in the official PHP distribution.
2.2) In mapscript.c, use ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf 
object", phpi_get_le_pdf() ); to get the PDF *, which can simply be passed on 
to msDrawPDF functions.

Does this make any sense?
Cheers,
Rod.

02/27/02 18:55:22 changed by dmorissette

phpi_le_get_pdf() and phpi_get_le_gd() are exactly what we needed.  I didn't 
know that this function existed, I guess I should have looked for it before, but 
anyway, now that we know that they exist (or can be added) then I think we have 
a viable solution to share GD and PDF handles with MapScript.

06/30/03 15:51:53 changed by dmorissette

  • version changed from 3.6 to 4.1.
Can't be done for 4.0, maybe in 4.1?

11/07/03 11:47:37 changed by huub@geodan.nl

Hi,

I'm trying to paste a nice layout together from a drawn map and scalebar and a
fixed legend with some texts in a layout template

Is it not a good suggestion to add a imageFromFile and imageFormURL to the
MapObject to work around the sharing resources problem?



so would then
MapObject -> imageFromFile ()  
MapObject -> imageFromURL () 

like
MapObject -> draw()  
MapObject -> drawScalebar()  
MapObject -> drawLegend()  

get imageobjects


Regards
Huub

11/07/03 12:32:38 changed by dmorissette

  • cc set to huub@geodan.nl, spencer@dmsolutions.ca.
I think it would really be cleaner to share gdImages otherwise we'll constantly
be adding more functions that just replicate what the PHP/GD module does already.

Note that you can already emulate imageFromFile() using a raster layer with
TRANSFORM FALSE, e.g. (untested code):

  $layer = ms_newLayerObj($map);
  $layer->set("type", MS_RASTER);
  $layer->set("transform", MS_FALSE);
  $layer->set("status", MS_ON);
  $layer->set("data", "/path/to/your/image.png");
  $map->set("width", $width_of_image);
  $map->set("height", $height_of_image);
  $img = $map->prepareImage();
  $layer->draw($img);
  $layer->set("status", MS_DELETE);  // make sure layer won't haunt us later

11/08/03 06:51:37 changed by huub@geodan.nl

Hi Daniel,

I copied the code an tried it, but the resulting imageObject is completely 
blank. I suppose I could experiment under which circumstance the original image 
file can be obtained in a mapscript imageobject.  Normally I might endeavour 
it, but since mapscript otherwise wraps so nicely around gl functionality i 
still prefer a simple function.

My strategy now is to save the drawn images to files and then do all the rest  
with the PHP imagefunctions. 

Huub

11/09/04 14:36:56 changed by assefa

  • milestone set to FUTURE.
Any news on this ? Target set to FUTURE.

11/09/04 17:21:11 changed by dmorissette

I think phpi_le_get_pdf() and phpi_get_le_gd() will be the way to go as I wrote
in comment #2. This would be a very welcome addition, but we'll have to wait for
a future release.