Skrol29 / opentbs

With OpenTBS you can merge OpenOffice - LibreOffice and Ms Office documents with PHP using the TinyButStrong template engine. Simple use OpenOffice - LibreOffice or Ms Office to edit your templates : DOCX, XLSX, PPTX, ODT, OSD, ODP and other formats. That is the Natural Template philosophy.
http://www.tinybutstrong.com/opentbs.php
69 stars 17 forks source link

Feature request: changepic from image-data instead of image-file? #13

Open rotdrop opened 3 years ago

rotdrop commented 3 years ago

Hi,

thank you for this nice package!

It would be nice to be able to insert picture (and maybe other file-data) from a PHP string instead of a file-name, as an additional option. Of course, one can always first copy the data to a temporary file on the server and then insert this file, but it would be convenient to be able to add the file-data directly without having to dump it to disk.

Skrol29 commented 3 years ago

Hi,

It could be done, but it would be a kind of bad practice because the picture binary contents would be stored into the PHP memory until the final merging is done. That could be heavy when you have a big picture or several pictures.

In another hand, when files to be replaced or inserted in the template are designed by a path, then it is done on the fly (one by one) during the final merging.

And also, doing a temp file is very fast with PHP :

$temp_pic_ress = tmpfile();
fwrite($temp_pic_ress, $binary_contents);
$temp_pic_path = stream_get_meta_data($temp_pic_ress)['uri'];
rotdrop commented 3 years ago

Actually, I cannot quite follow you concerning the "bad practice", although I agree that it is only useful for comparatively small images, like a logo in the header of a letter, or the copy of a signature. It is clear that this can be handled with a temp-file, OTOH, OpenTBS then just reads the file into memory anyway (looking at _DatPrepare())?

I think I can come up with a pull request (here it is: #20)