How to convert .ndpi and .vms files into dzi - php

I have a problem with the openseadragon. I cant convert the ndpi file into deep zoom image(dzi) and it cant directly open the ndpi image.
$file_name = '22R23003.ndpi';
$file = '22R23003';
$converter = new Oz_Deepzoom_ImageCreator();
$converter->create( '../uploads/'.$file_name,'../dzi/'.$file.'.xml');

Related

Storing Image path using Laravel

I have a controller which handles the upload functionality of the music file. The controller uses this Laravel getID3 package to parse the metadata from the music file and store in the database.
My code looks like this
if($request->hasfile('songs')){
foreach ( $request->file('songs') as $key => $file){
$track = new getID3($file);
$tifo = $track->extractInfo();
$artistName = $track->getArtist();
$songName = $track->getTitle();
$albumName = $track->getAlbum();
$extension = $track->getFileFormat();
$thumbnail = $track->getArtwork(true);
$thumbnails = 'artwork-'.time().'.'.$thumbnail->getClientOriginalExtension();
$location = time() .uniqid().'.' . $extension;
$file->storeAs('public/songs',$location);
//$file->storeAs('public/sthumbs',$thumbnails);
$file = new MusicUpload();
$music_upload_file = new MusicUpload();
$music_upload_file->user_id = Auth::user()->id;
$music_upload_file->filename = $songName;
$music_upload_file->extension = $extension;
$music_upload_file->artistname = $artistName;
$music_upload_file->albumname = $albumName;
$music_upload_file->location = $location;
$music_upload_file->thumbnail = $thumbnails;
$music_upload_file->save();
}
}
What I want to do is to store both the music file as well as the thumbnail of the file in the database.
Here the $thumbnails will store the image in the specified folder but the image is unreadable, i.e. it has the same file size as the music and doesn't contain the artwork which is to be stored and retrieved.
If I don't include the $thumbnails part, the package default stores to the temp folder which is inaccessible to the controller.
So how do I write the code such that the thumbnail(artwork) of the music gets stored in the correct folder and it can display the output too.
You can store it to storage folder.
Storage::disk('public')->put($location,File::get($file));
Don't forget to run php artisan storage:link

mpdf - images from a url won't load in generated pdf

I'm trying to load images from a http url but they won't display in my generated pdf.
$this->layout = '//layouts/pdftemplate';
$pdf = Yii::app()->toPDF->mpdf();
$pdf->shrink_tables_to_fit = 1;
$pdf->defaultfooterline = false;
$stylesheet = file_get_contents(Yii::app()->basePath.'/../webroot/admin/themes/admin/css/formbuilder-print.css');
$pdf->WriteHTML($stylesheet, 1);
$pdf->WriteHTML($_POST['html_string']);
$pdf->Output(sys_get_temp_dir()."/test.pdf", 'F');
I'm passing the html to the php function in an ajax call. The images are on Amazon CloudFront.
Update
Thanks to Asped and Latheesan Kanes I got the issue resolved. I also used PHP's DOMDocument class to replace the image urls with the local copy of the image. This is for future reference if anyone also runs into a similar issue
$doc = new DOMDocument();
#$doc->loadHTML($_POST['html_string']);
$imgs = $doc->getElementsByTagname('img');
foreach ($imgs as $img){
$src = $img->getAttribute('src');
$name = explode('?', basename($src));
$name = $name[0];
$tmp = sys_get_temp_dir().'/'.$name;
copy($src, $tmp);
$img->setAttribute('src', $tmp);
}
$html = $doc->saveHTML(); // you can write this to the pdf. $pdf->WriteHTML($html);
I had a similar issue once displaying an SVG file in the pdf.. it would not work. Then I converted it to a PNG (on the fly), stored locally in a temp folder, and passed the temporary file to mDPF, which helped.
UPDATE - Actually now I remember I didn't even had to convert it, I just had to store it locally in a temp folder..

Cakephp how to browse file?

my question is how to get the content of a file from a input file
becausethe only thing im getting is the name of the file not the
full path of the file.
$handle = file_get_contents($this->data['btnBrowse']);
$absolute = basename($this->data['btnBrowse']);
var_dump($handle);
var_dump($absolute);
This should work:
$file = new File($dir);
$contents = $file->read();
$file->close();

sugarCRM add document from script

I am trying to add Document to Sugar object (client) from PHP script. I have a directory of files (on the same server where sugarCRM is installed) and xls with sugar objec ID and filename). PHP Script should add correct filename to specific sugar object (identified with ID). I can read XLS this is no problem, I can also get instance of sugar object (retrieve by ID), but I have no idea how can I assign the file to sugar. I was trying with Document, and upload_file.php, but those seem to be usable with uploading single file with html Form.
How can I automate this task, copy files with correct filename to cache\upload and create Document related to my Customer from PHP Script? I would prefer not to use SOAP if it's not necesarry...
Edit:
I was able to save document and revision, but something is wrong, and file can't be downloaded from browser ("incorrect call to file")
My Code so far is:
require_once('include/upload_file.php');
$upload_file = new UploadFile('uploadfile');
$document->filename = 'robots.txt';
$document->document_name = 'robots.txt';
$document->save();
$contents = file_get_contents ($document->filename);
$revision = new DocumentRevision;
$revision->document_id = $document->id;
$revision->file = base64_encode($contents);
$revision->filename = $document->filename;
$revision->revision = 1;
$revision->doc_type = 'Sugar';
$revision->file_mime_type = 'text/plain';
$revision->save();
$document->revision_id = $revision->id;
$document->save();
$destination = clean_path($upload_file->get_upload_path($document->id));
$fp = sugar_fopen($destination, 'wb');
if( !fwrite($fp, $contents) ){
die("ERROR: can't save file to $destination");
}
fclose($fp);
WORKS! I Hope this will help someone
I have corrected 3 lines from code abowe:
//$document->revision_id = $revision->id;
//$document->save();
$destination = clean_path($upload_file->get_upload_path($revision->id));

ODT to PDF conversion using PHP/OO

I am currently trying to convert an ODT to PDF using OO silently from PHP. Here is the code for that:
function MakePropertyValue($name, $value,$osm){
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
function odt2pdf($doc_url, $output_url){
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
$args = array(MakePropertyValue("Hidden",true,$osm));
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
$oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
$aFilterData = array();
$aFilterData [0] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$aFilterData [0]->Name = "SelectPdfVersion";
$aFilterData [0]->Value = 1;
$obj = $osm->Bridge_GetValueObject();
$obj->set("[]com.sun.star.beans.PropertyValue",$aFilterData );
$storePDF = array();
$storePDF[0] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$storePDF[0]->Name = "FilterName";
$storePDF[0]->Value = "writer_pdf_Export";
$storePDF[1] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$storePDF[1]->Name = "FilterData";
$storePDF[1]->Value = $obj;
$oWriterDoc->storeToURL($output_url,$storePDF);
$oWriterDoc->close(true);
}
$output_dir = "C:/wamp/www/cert/pdf/";
$doc_file = "C:/wamp/www/cert/output2.odt";
$pdf_file = "output2.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
odt2pdf($doc_file,$output_file);
I have managed to get it to convert to PDF/A-1a as can be seen, however it still does not preserve the fonts being used. If I convert this from within the GUI in Open Office, then the fonts are kept. What's wrong?
UPDATE: I decided to stop converting to PDF and do a silent print of the odt to the printer with Open Office using exec() in PHP.
As an additional note, make sure to switch off Font substitution on the printer driver to prevent any font substitution when printing to a PostScript printer.
Try by first converting the ODT to HTML ( to maintain formatting ) by using this library
https://gist.github.com/1918801
and later use this FPDF library to convert from html to pdf
I guess FPDF wont support so easily to convert from html so there is a plugin for that FPDF
here is the link for the plugin
plugin for FPDF to convert from HTML

Categories