How to load an SVG and a referenced PNG from a REST service at the same time? - rest

I'm trying to create a web service in PHP that can deliver an SVG with reference to a PNG raster image. Both the data for the SVG as well as the binary PNG image come from a MySQL database on the server.
Option A: Encode the PNG data in base-64 and embed it directly in the SVG, such as:
<image xlink:href="data:image/png;base64,..."/>
Concerns: 30% heavier load than loading it as pure binary and noticeable delay when loading it with Postman (or is this just because of Postman).
Option B: Call the PNG data as binary and save it as a file on the file system, then call the SVG file, which would then reference the physical PNG file.
Concerns: Involvement of the file system (which implies I need to start managing physical files, expiration dates etc).
Is there perhaps another way that an SVG can reference the binary data on the fly without it having to be on the file system?

To accomplish something similar (in my case sending data for SVGs with additional data about each file as binary files, which are much smaller than sending xml, text, or json) - I use CBOR. In my case, I compress the SVG using LZString compression first, and add this along with additional data attributes to a JSON object. Then I convert the JSON object to CBOR. I think CBOR can handle your base 64 data without any need for conversion - more information about it is here: cbor.io
I found a PHP library for CBOR here: https://github.com/2tvenom/CBOREncode
This may not be the way to go at all for you, but I thought I'd throw it out there just in case.

Related

keep/copy XMP with libexif

I try to add a thumbnail to a JPEG picture using libexif.
For now I'm borrowing the code from exif (the command line tool that is shipped by the libexif team).
However I noticed the XMP tags get deleted from the metadata. There is an old bugreport here.
I tried to see how to achieve this anyway with libexif but I don't really understand how to get the XMP from input file and put it in the output file. I just want to copy all XMP data, I don't need to extract anything of it.
I saw there is a TAG EXIF_TAG_XML_PACKET in exif_tag.h but couldn't figure out how to read/write this tag.
A related solution is in this SO answer but it looks complicated. I'm not familiar coding in C.
Is it actually possible to keep all XMP when using only libexif API? Have things changed in recent years on that? How would you write this in code?
Thanks
I believe it should be somewhat straightforward. XMP fields are described in the ISO/Adobe standard. Regular Kotlin/Java/Android file I/O and some string manipulation should be all that is required.
I would start out by becoming intimately familiar with ISO 16684-1:2019. Then, write a method for your jpeg file class that grabs all the XMP fields. Store those fields in a temp file (to prevent difficult to recover data loss in the event of your code or libexif crashing). Hand the file off to libexif. Generate the thumbnail. Finally, when that's done you can restore the XMP fields. If the thumbnail is stored in an XMP field as well (and it sounds like it is), it may be easier to concatenate that field with the other ones which were already grabbed, updating the temp file so that it contains EVERY XMP field, before adding all of the XMP fields back to the jpeg.
Unfortunately, I do not currently have the time to read a 50 page ISO standard, synthesize the information, and then write the code to implement the solution. Here's a link to the standard at least, to get you started.
https://www.iso.org/obp/ui/#iso:std:iso:16684:-1:ed-2:v1:en

How can I decrypt the Triplestore files of an RDF4J database?

I am currently trying to read the files of an RDF4J triplestore from the universAAL platform and put them into an InfluxDB to merge the data from different smart living systems.
However, I have noticed that the individual index files of the Native repository are encrypted/unreadable (See image below).
Is there any experience from the community on how to get human readable content out of the RDF4J files (namespace, triples.prop, triples-cosp, triples-posc, triples-spoc, values.hash, values.dat, values.id) and merge them into another database?
The documentation of RDF4J did not help me here, so I could not create a decent export.
Encrypted File from Triplestore
The files are not encrypted, they're simply a binary format, optimized for efficient storage and retrieval, used by RDF4J's Native Store database implementation. They're not meant for direct manipulation.
The easiest way to convert them to readable RDF is to spin up a Native Store on top of them and then use the RDF4J API to query/export its data. Assuming you have a complete set of data files it should be as simple as something like this:
Repository rep = new SailRepository(new NativeStore(new File("/path/to/datafiles/");
try(RepositoryConnection conn = rep.getConnection()) {
conn.export(Rio.createWriter(RDFFormat.TURTLE, System.out));
}
finally {
rep.shutDown();
}
Obviously, replace System.out with a FileOutputstream if you want to write the data to file rather than the console. And change RDFFormat.TURTLE to something else if you want a different syntax format.

ObjectScript file create from stream

how can I create file (PDF file for example) from binary stream I have stored in global? I have stream stored in caché global and I need to create and save the file created by the stream using ObjectScript.
Thanks :)
It is not so easy. There is only one official way to create pdf in Cache, and it is ZEN reports. With ZEN reports you could create not only pdf, also possible to make html, xlsx. ZEN Reports used Apache FOP for generating it, any other ways also possible, but you should do it only by yourself.
Or maybe I misunderstood you, and you mean that your binary stream already contains PDF, and you just want to save it to some file. If so, you just have to copy your globalstream to filestream, with code like this:
set fs=##class(%Stream.FileBinary).%New()
set fs.Filename="c:\temp.pdf"
set tSC=fs.CopyFrom(yourStream)
set tSC=fs.%Save()

How to preserve XMP metadata in Objective C?

I need my photo-editor app to preserve unknown metadata entries that were existing in the original photo that was opened by my app (for example, non-standard XMP meta-data)
I tried to use the Apple's built-in meta-data read/write meta-data, with no success.
Is there a way to just copy all existing meta-data to a buffer, write it as-is and then change only specific entries?
Yes.
Use Adobe XMP SDK.
Read the metadata from the image when you open it using:
SXMPFiles myFile;
ok = myFile.OpenFile(filename, kXMP_UnknownFile, opts);
myFile.GetXMP(_meta); // _meta is a data member of the class that represents your photo (probably a subclass of NSDocument).
When saving the image, write the image content, then write _meta to the output file using SXMPFiles.PutXMP(...), and then set specific metadata entries that you like.
See Adobe XMP programming guide for more details about reading and writing XMP metadata.

PDF file stored as BLOB, view in a webpage perl

I have a code that handles displaying a blob from a local Oracle database. I store both JPG and PDF files as blob. I could view the JPG file, but not the PDF. I have checked these
$self->content_type('image/jpg')
to
$self->content_type('application/pdf').
And the Blob does have data. I checked the length and it has "184546".
All I get when I click the link for the pdf file is a blank page with the title GETIMAGPAGE(application/pdf).
Any help or pointers would be greatly appreciated.
Also, How can we have the content_type to enable two different mime_types? For example in my case both image as well as pdf, depending on what we get?
File::MMagic can recognize the type of data using magic numbers.
use File::MMagic;
$magic = File::MMagic->new;
$self->content($blob);
$self->content_type($magic->checktype_contents($blob));
If you don't want to require a native/plugin PDF reader, perhaps FlexPaper might fit your needs.