Delphi for PHP. Lets draw something

I was asked if it is easy to draw something in DfPHP.

Hm, yes it is. There is a class called Canvas… Oh!!! something familiar!

First idea was to use a PHP drawing by creating a PNG file which then uploaded to the page. It was not very fast and sometime would make you page looks ugly.

So,… after some research a proposition was made to use of one of the best Free JavaScript based Drawing libraries  – JSGraphics by Walter Zorn – and now it is part of DfPHP.

As a result, Canvas class and Bevel, Shape, PaintBox objects are based on this Js code … and you should find a few samples included with the product.

Please notice that you can still use PHP to perform drawing – see here. But as you know:

  • GD library is required
  • you would need to actually create an image stream which then will be sent to client – server side processing
  • If you are not using layers on your page then you will get an element which is “boxed” – nothing else is being placed on it except what you have already drawn.

There is nice article at Zend DevZone about image generation using PHP itself.

Difference with current implementation using JS based library – there is no image stream – you need just DHTML and JavaScript support in your browser. Then you can draw anywhere on the page without requirement to have image placeholders.

But again it is your choice as programmer what is better for you in each situation.

One thing you need to remember – I will try to add this as soon as VCL for PHP is out is to able to print. For that setPrintable(true); call has to be made for jsGraphics instance.

This entry was posted in Delphi. Bookmark the permalink.

2 thoughts on “Delphi for PHP. Lets draw something”

  1. Clive says:

    Do you know how to access the Canvas property of the PaintBox component? It seems to be implemented as a protected member?!

    Your advice would be much appreciated.

  2. There is no direct need for property since it is a JS class.
    Canvas PHP class is used in Shape component mostly.
    What you have in PaintBox is a JS class which can be accessed and I think Demos folder has an example on how to draw from JS event at runtime.
    Since VCLfPHP is an open source project, property could be exposed at any point with minimum code change.
    Also, there is no need for you to use a PaintBox itself in case of PHP code, but instead create your own instance of Canvas (see code of PB for details) and draw what you’d like.

Leave a Reply