I saw many post about changing picture in OpenTBS but I don't understood how to do that.
I have a .odt file wich has an image and i need to replace it from php with another one.
From documentation i see the Exemple: [ onshow.x;ope=changepic] but I have no idea where I have to put this line.
I've also tried to use this code below but nothing happens.
"ticket.odt" has an image (it has $PicRef descripton) which I would like to change.
$TBS= new clsTinyButStrong;
$TBS->PlugIn(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->LoadTemplate("Ticket/ticket.odt");
$TBS->PlugIn(OPENTBS_CHANGE_PICTURE, $PicRef, $logo );
As documentation $PicRef is a string that is saved in the Title or the Description of the picture and $logo is the path for picture file that will be copied inside the document
Could someone explain me how it'works and what i have to do?
Example using command OPENTBS_CHANGE_PICTURE:
PHP side:
$TBS->PlugIn(OPENTBS_CHANGE_PICTURE, 'my_picture', 'logo.png');
$TBS->Show(OPENTBS_FILE, $file_name);
Template side:
In the ODT template do a right-click on the picture you want to be replaced then you have the contextual menu. In the contextual menu, select Properties. Then in the tab Options, change the property Name to 'my_picture'.
When running the script, the picture will be replaced.
Example using parameter changepic:
PHP side:
$TBS->VarRef['x'] = 'logo.png';
$TBS->Show(OPENTBS_FILE, $file_name);
Template side:
Put the TBS field [onshow.x;ope=changepic] somewhere in the normal text after the picture you whant to be changed.
Or
Put the TBS field [onshow.x;ope=changepic;tagpos=inside] in the property Name of the picture (see previous example).
Related
There is a simple two-column table on a website: product name and product image. It's very easy to render in HTML.
The task would be creating an Xlsx file with these columns.
The images are not stored locally but all of them are remote images with full URL.
The export contains ~100-200 rows.
I tried to create a resource with imagecreatefromjpeg and adding it with MemoryDrawing but it took a huge amount of resources.
I tried with Html helper's toRichTextObject and a simple tag but got empty result.
How is it possible to add a remote image to a PhpSpreadsheet cell? It doesn't need working offline, it's fine to load the remote images when the file is opened.
As #FabriceFabiyi mentionned in his comment, and after reading:
PhpSpreadseet documentation on drawing.
PHP documentation on file_get_contents.
PHP documentation on file_set_contents.
This worked for me:
$image = file_get_contents('https://website.com/path/to/image');
$imageName = 'a_nice_image_name';
//You can save the image wherever you want
//I would highly recommand using a temporary directory
$temp_image=tempnam(sys_get_temp_dir(), $imageName);
file_put_contents($temp_image, $image);
// And then PhpSpreadsheet acts just like it would do with a local image
$drawing->setPath($temp_image);
$drawing->setHeight(36);
$drawing->setWorksheet($sheet);
$drawing->setCoordinates('B15');
More on temporary directories in the PHP docs:
sys_get_temp_dir()
tempnam()
There is an example how add image to your excel export:
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Paid');
$drawing->setDescription('Paid');
$drawing->setPath('/images/image-1.png'); // put your path and image here
$drawing->setHeight(30);
$drawing->setCoordinates('A5');
$drawing->setOffsetX(110);
$drawing->setRotation(25);
$drawing->getShadow()->setVisible(true);
$drawing->getShadow()->setDirection(45);
$drawing->setWorksheet($spreadsheet->getActiveSheet());
Specifying coordinates for the image might help, as per the examples and the documentation
$objDrawing->setCoordinates('A3');
Note that an image isn't in a cell/column/row, but overlaid over the main sheet at the same position as that cell/column/row
So i have this one small thing im doing, and the thing is: It generates QRcodes using the google qrcode api. Id like to download the generated qr code with the press of a button into a /img folder i have inside the folder my php file is located at, and id need it to save with a numerical number which is the button's id. (it has like 120 buttons and each one has a 0-120 id, id like to save the qrcode that belongs to the button 10 with a name like 10.png) any ideas on how to do so?
__
Little edit: as Man Manam pointed out my question is: I have the image link, i want to save it in my server. Sorry for the confusion.
As you're using Google for creating the QR code, I assume you have a code like this somewhere:
$ga = new \Google\Authenticator\GoogleAuthenticator();
$qr_link = $ga->getUrl($username, $_SERVER['HTTP_HOST'], $secret);
// then you'd display that code with <img src="$qr_link">
What you need to do is to simply download that QR code instead of showing in browser. You can use curl for this or, even simpler, just fopen/file_get_contents if allow_url_fopen is set to ON in php.ini
$image_bin = file_get_contents($qr_link);
file_put_contents($target_file_on_filesyste, $image_bin);
So I'm making a notepad app in PHP, but I want to add the ability to share the file amongst your peers or something.
It's based on AJAX, and it saves the file automatically, and the file is named to what your IP address is after being hashed in md5.
What I want to do is maybe go to /view/837ec5754f503cfaaee0929fd48974e7, while the actual text file is located at /notes/837ec5754f503cfaaee0929fd48974e7.txt
I know I'll have to use file_get_contents(), but I don't know how to display it on a page.
I could just have it link to the .txt file, but I don't want it raw. I want it to have some style.
How would I go about doing this? Where can I start?
First you would need a way to store a variable in the URL (the file name). This can be easiest done using the querystring.
So the link to a file for your user to see would be '/view/?file=MYFILENAME'
This would then be interpreted by your php (this could also be wrapped in AJAXy goodness) into a path to retrieve the text file from.
view/index.php
//Fetch the file based on the get variable
//Note the relative path
$file = file_get_contents('../notes/'.$_GET['file'].'.txt');
//Print the file. You can also dress it up or wrap it in HTML tags
echo $file;
When displaying the text file, there is some built in functions that will help. Most notable nl2br() which takes the new line characters in a text file and makes them into html <br> tags.
More reading on the GET array can be found here
I have a word document (template) which contains some images that I have to replace with others that are present on the drive. The images that exist in the documents are currently blank. And the ones that will replace them have some text written on them. One way to do was to edit each document and then by double-clicking the image I use the Pbrush to edit the image. Other way is below.
I used PHPWord to do the job. Open the document and replace the image in the word/media.
The problem: At first look it looks like the image has been replaced. Also, if I check through zip/winrar the images are replaced. But when I double click the image in the doc I see the old(blank) image in PBrush. I want the new edited image to show up. Or an alternate way to do the job.
This function does not exist in the original PHPWord but found it as the quick fix to do the job. (PhpWord/Template.php)
public function replaceImage($path,$imageName) {
$this->_objZip->deleteName('word/media/'.$imageName);
$this->_objZip->addFile($path,'word/media/'.$imageName);
}
My Code:
$PHPWord = new PHPWord();
$document = $PHPWord[$i]->loadTemplate('ALL_FILES/Template.docx');
$document->replaceImage($oldImage, $newImage);
$document->save('ALL_FILES/genForms/updatedDoc.docx');
P.S. Hope it is clear what I am trying to say. If need be, I can upload a test document somewhere, in case the problem is not clear.
I'm currently trying out the TinyButStrong library with openTBS plugin to edit an OpenOffice writer template.
If I correctly understand, you can change a default picture to something else using this:
[b.number;ope=changepic;from='pic_[val].png';default=current;adjust]
I tried changing the from='pic_[val].png' to from='example.jpg', this didn't change the picture however.
Anyone knows how to get this working? Help will be greatly appreciated.
Put a fixed value in parameter "from" should force the image (it worked for me).
If your field has been merged (that is it does not appear in the result file) and you have no error message, then having the image unchanged means that the target file cannot be found.
I think the 'example.jpg' file should be placed in the folder with the script that manages TBS and OpenTBS. Otherwise, you have to specify a path.
You don't actually need to the 'from' parameter to just switch a picture out. OpenTBS gets the path of the picture from the first parameter - in your case b.number (which hopefully contains a path to an image). Adjust is also not required, unless you are resizing the picture.
[b.number;ope=changepic;default=current;]
Assuming:
$b->number = '/path/to/image.png'
Also keep in mind, if b.number is a block, you may need to define your block boundary for the data to populate. (If you are able to see the path in the $TBS->PlugIn(OPENTBS_DEBUG_XML_SHOW) mode don't worry about this) Try using [b.number] if you are not sure your data is being processed.