How can I convert BASE64 encoded HTML to GIF using ColdFusion? - html

I am receiving a BASE64 encoded string from a WebService. The string represents an HTML page, and I can use built-in ColdFusion functions to convert and display it. However, I need a GIF representation of the HTML page, and I'm wondering if there's any way to do this using ColdFusion.
NOTE: The website I'm working on is ColdFusion 8.
UPDATE: As it turns out, the vendor gave me incorrect instructions (different from their documentation). I don't need to output a GIF of the document they are sending, so this is a non-issue now. However, seeing as the question has received 6 upvotes already, I'm going to leave the it open, as I'm curious if there is - or will be - an answer someday.

You could save the html to the file system, and use this technique for creating URL Thumbnails

Since CFIMAGE's writeToBrowser doesn't allow you to output a GIF (as you've no doubt found out), you'd have to take the image and save it to the filesystem as a gif, then write an HTML IMG tag pointing to that GIF file.

You can't write a gif but you can take the base64 and write it to the browser as a png.

Related

Angular Base64 file upload as JSON

I'm trying to create a reusable directive in my app that allows for files to be encoded as base64 then uploaded via JSON.
I haven't seen my resources on the web talking about this approach. I've mostly only been able to find Angular file uploads via form data.
Can anyone shed some light on this topic?
This link
may prove interesting.
Basically he state that Base64 encoded data is 33% larger and takes longer to process than binary.
htmltrocks has an interesting
article regarding integrating the canvas element into your App.
It shows use of the HTML5 canvas toDataURL() method which converts to Base64.
See also:
How to convert image into base64 string using javascript

Can browsers cache the embedded base64 images also?

I was wondering if any of the modern browsers actually cache the embedded images -- base64 strings, or not?
Also is that a possibility in the near future? based on the official documents by either W3C or major browsers.
I don't think so, because you're missing an Resource Identifier as the key for the cached image. With embedded images you only have the data itself.
Furthermore a potential conditional request for inlined images must be at the level of the HTML document containing it. The inlined image is just data with no additional request. But HTTP does not support something like conditional requests for parts of the data.
As I understand it, if the base64 string is part of the HTML document (inline) then it will both have to be downloaded and parsed as an image each time the document is downloaded - there is no way to cache fragments of documents. If it is a background image in an external CSS file then it can be cached with the CSS file, but will still need to be parsed with every request. I have also read that base64 encoding adds circa 30% overhead on top of the image bytes, but this can largely be negated by gzipping.
Browsers can cache downloaded files. If the Base64 string is in a text (or JSON) file then it can be cached. This data can then be used directly in the HTML (or if JSON, parsed with Javascript and used with HTML).

How can I show a TGA image in a <img> tga?

I have a TGA image encoded in Base64
https://gist.github.com/984770
But it doesn't show on the browser.
Is there a way to show a TGA image on the browser or it is not supported? Is there any client side technology I could use to achieve this?
It's not supported.
I assume there probably are Java or ActiveX plugins that can do it, but it's going to be complicated, cumbersome, have spotty support, and of course won't work with base64 data.
If it's just a few images, consider converting them to JPG, PNG or GIF manually, depending on what type of image they contain.
If it's many images and you need an automated solution, a good way would be to employ a server-side script that calls e.g. ImageMagick, and creates a JPG thumbnail from the image.
You could easily send the base64 data to the script using Ajax for example, receive the name of the converted file in return, and create an <img> element pointing to it.

Can I use images without extension in <img>? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is it safe to serve an image on the web without an extension?
I'd like to use something like <img src="advertisements/12" style="border: 1px solid"> in a page. FireFox won't display it, which makes me think I have to have a file extension for the file. Am I right here (for the other browsers too), or does FF like mime types?
EDIT
I've tried all sorts of stuff and it still won't work. I now put an extension on the file correctly (.swf for Flash, for example). I've changed the directory, etc etc. When I call file_exists(), The file is there, all happy and such, however I absolutely cannot get it to render on the page. It could either be a .PNG in an img tag, or a Flash object. Neither works. What am I doing wrong :-(
Also, if I rename a non-uploaded file to the file the script is looking for, that works fine, but the uploaded ones don't...
Yes, you should be able to.
Browsers initially don't look at the filename, they look at the MIME type listed in the Content-type header in the response from the HTTP server. If the content type is image/jpeg, or png or gif or whatever, things are good and it will happily render the image.
If there is no valid MIME type, some browsers will try to guess what the type is. They'll look at the extension of object being request, or they'll look at the first few bytes. If that fails, then you get a redex.
That used to cause some woes back in the early days of Firefox / Firebird, because it was strict about mime types and often refused to render something without a valid MIME type. IE made a guess, and so many sloppy web servers would serve up pages that would render fine in IE, but not in others. These days though, things are much better.
So, as long as your web server is providing the right MIME type when the img object is requested, you'll be good to go. If you are having problems, check what your web server is doing when "advertisements/12" is requested.
What is the server returning? The file extension isn't used for anything, really. The browser is checking for the Content-type header, which should be something like image/jpeg or whatever type of image you're serving.
This is used pretty often in sites which dynamically serve images, often from a database. I've seen plenty of image URLs like image.aspx?id=37 which, while it technically has an "extension" doesn't really mean that it's an image. It's all in the HTTP header values.
Providing a MIME type might help, although the server should theoretically be providing the correct one. If it's a specialized PHP (or similar) script that's serving up the image, you have to make sure you set the HTTP Content-Type header to the appropriate MIME type.
If you want to avoid using the <img> tag, you can use <div> in conjuntion with CSS backgrounds, but that's not going to help if the browser doesn't recognize advertisements/12 as any known image type.
2022 Edit:
Wow! Well, it worked good enough back then... But, for modern day detection there is https://www.php.net/manual/en/function.exif-imagetype.php ...with webp detection as of v7.1.
I found myself with similar image viewing problems after renaming images uploaded from web forms. Since I could have a mix of gif, jpg, jpeg, or png files I went looking at the file properties.
What I ended up doing was checking the MIME type (which is usually within the $_FILES array while processing the uploaded files) and appending an associated extension to the file name.
if($_FILES[$fieldname]['type'][$key]=='image/gif') {
$ext='.gif';
}
if($_FILES[$fieldname]['type'][$key]=='image/jpeg') {
$ext='.jpg';
}
if($_FILES[$fieldname]['type'][$key]=='image/pjpeg') {
$ext='.jpg';
}
if($_FILES[$fieldname]['type'][$key]=='image/png') {
$ext='.png';
}
List of common image mime types.
--Which did fix my problem as my browser was trying to download my images as binary files without the filename extension.
Server - Debian, Apache 2.2, PHP 5.3
Web Client - Kubuntu 11.10 ,Firefox

HTML Canvas and saving the data on the server

Say I've written a simple app that draws circles in browser. Now I'd like to let people save their pictures. How would I store the data on the server? Which format would be the best option? Should I simply store the relevant html? What would be the case when I would want to make a custom format that is stored on the server and parsed back to html canvas when loaded?
How would I store the data on the server?
Which format would be the best option?
Since they are just circles, you probably just need starting coordinate, size, line thickness, and colour. Sounds like its easy enough to store with SQL.
Should I simply store the relevant html?
What HTML? Drawings on canvas are not exposed in the DOM. That's why canvas is (currently) awful for accessibility (unlike SVG).
What would be the case when I would want to make a custom format that is
stored on the server and parsed back to html canvas when loaded?
I'd transport it as JSON and then loop over the dataset with JS to redraw it.
canvas.toDataURL should allow you to do such things. check out canvaspaint.org's source code to see how to save on local computer and on server.
This might help: Save a <canvas> as a file in a form.
This demo shows how to save locally -- though, for me at least, Save PNG (etc.) work in Firefox but not Chrome.