http://intentlab-io12.appspot.com/samples.zip
(Unzip them somewhere locally where you can edit the files.)
(Many thanks to Ilmari Heikkinen and html5rocks)
Sample pictures in $REPO/sample-pictures
The three chief virtues of a programmer are: Laziness, Impatience and Hubris.
var intent = new WebKitIntent({
"action":"http://webintents.org/pick",
"type":"image/*"
});
navigator.webkitStartActivity(intent, onSuccess, onFailure);
An Intent object has three parts:
The Intent type parameter governs the passed data and the result type
schema.org types
navigator.webkitStartActivity(intent, onSuccess, onFailure);
function onSuccess(result) {
// For the "image/*" MIME type, result is a Blob or a URL
if (result instanceof Blob) {
...
} else {
...
}
}
Replace implementation for this:
index.html)loaded() function)loadImageFromUrl)
var intent = new window.WebKitIntent({
"action": "http://webintents.org/save",
"type": "image/*",
"data": blob}); // <-- the image to be saved!
var onSuccess = function(data) {}
var onError = function(data) {}
window.navigator.webkitStartActivity(intent, onSuccess, onError);
// No, really. That’s it.
var canvas = $('#container canvas')[0];
var blob = createBlobFromCanvas(canvas);
var intent = new window.WebKitIntent({
“action” : “http://webintents.org/save”,
“type” : “image/*”,
“service”: “chrome-extension://npoipmeppdioagbkigdlnpxxxhnolaog/save.html”
“data”: blob });
var onSuccess = function(data) {}
var onError = function(data) {}
window.navigator.webkitStartActivity(intent, onSuccess, onError);
window.webkitIntent object.
if (window.webkitIntent) {
// We are servicing an Intent!
handleIntent(window.webkitIntent.data);
}
{
"intents" : {
"http://webintents.org/save": [{
"type": [ "image/*" ],
"href": "save.html",
"title": "Filtamatic",
"disposition": "window"
}]
}
…
}
See manifest.json documentation for Chrome App development
Replace this functionality:
2_save" directory.
// Display the image to be saved.
var loaded = function() {
if (window.webkitIntent.data instanceof Blob) {
imageURL = webkitURL.createObjectURL(window.webkitIntent.data);
} else {
imageURL = window.webkitIntent.data;
}
$('#image').attr("src", imageURL);
$('#close').click(closeSave);
}
var closeSave = function() {
window.webkitIntent.postResult("");
}
<html><body onload="loaded()"><center>
Right click and use <b>Save Image As...</b> to save.
<p>
<img src="">
<p>
<input type=button id=close>Close</input>
</center></body></html>
{
"name": "SimpleSave",
"icons": { "16": "save16.png" },
"version": "2",
"intents": {
"http://webintents.org/save" : [{
"type": ["image/jpg", "image/png", "image/gif"],
"title": "Save Image",
"path": "save.html",
"disposition": "inline"
}]
}
}
See manifest.json documentation for Chrome App development
<intent action=”http://webintents.org/save” type=”image/*” href=”services/save” disposition=”window” title=”Save an image” />
var intent = new WebKitIntent({
"action":"http://webintents.org/save", "type":"image/png", "data":blob});
navigator.webkitStartActivity(intent, onSuccess, onError);
Receive Intent
if (window.webkitIntent) {
handleIntent(window.webkitIntent.data);
}
Send Response
window.webkitIntent.postResult(reply);Receive Response
function onSuccess(data) { handleResponse(data); }
<button id="pick" onclick=”intent-pick”>Pick image ...</button> <button id="save" onclick=”intent-save”>Save ...</button>
function intent-pick() {
var intent = new WebKitIntent("action":"http://webintents.org/pick", "type":"image/*");
navigator.webkitStartActivity(intent, onSuccess, onFailure);
}
function intent-save() {
var intent = new WebKitIntent({"action":"http://webintents.org/save", "type":"image/jpg",
"data":getImageData());
navigator.webkitStartActivity(intent, onSuccess, onFailure);
}
// Get a canvas for the image element
var ctx = document.getElementById('canvas').getContext('2d');
// Get image data from canvas. Pixels are in imageData.data
// width and height are in pixels.width and pixels.height
var imageData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height)
// Write image data to canvas.
ctx.putImageData(imageData, 0, 0);
// See http://www.html5rocks.com/en/tutorials/canvas/imagefilters/ for
// details and example filters.
{
"name": "Filtamatic Image Editor",
"version": "2",
"icons": { "16": "edit16.png",
"128": "edit128.png" },
"intents": {
"http://webintents.org/edit" : [{
"type": ["image/jpg", "image/jpeg", "image/png", "image/gif"],
"title": "Filtamatic",
"path": "edit.html",
"disposition": "window"
}]
}
}
See manifest.json documentation for Chrome App development
Expose the existing functionality of Filtamatic as an "edit" intent service.
... or do something else exciting
postResult to the intent