Skip to content

Commit

Permalink
Final ammend for version 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
betamax committed Jan 13, 2011
1 parent da827e8 commit 74ed2cb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
test*.html
8 changes: 4 additions & 4 deletions jquery.getimagedata.js
@@ -1,10 +1,10 @@
/*
*
* jQuery $.getImageData Plugin 0.2
* jQuery $.getImageData Plugin 0.3
* http://www.maxnov.com/getimagedata
*
* Written by Max Novakovic (http://www.maxnov.com/)
* Date: Mon Sep 13 2010
* Date: Thu Jan 13 2011
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
Expand All @@ -15,13 +15,13 @@
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2010, Max Novakovic
* Copyright 2011, Max Novakovic
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://www.maxnov.com/getimagedata/#license
*
*/

// jquery.jsonp
// jQuery JSONP
(function(d,l){function w(){}function Q(a){p=[a]}function g(a,h,i){return a&&a.apply(h.context||h,i)}function x(a){function h(b){!j++&&l(function(){m();n&&(q[c]={s:[b]});y&&(b=y.apply(a,[b]));g(a.success,a,[b,z]);g(A,a,[a,z])},0)}function i(b){!j++&&l(function(){m();n&&b!=B&&(q[c]=b);g(a.error,a,[a,b]);g(A,a,[a,b])},0)}a=d.extend({},C,a);var A=a.complete,y=a.dataFilter,D=a.callbackParameter,E=a.callback,R=a.cache,n=a.pageCache,F=a.charset,c=a.url,e=a.data,G=a.timeout,o,j=0,m=w;a.abort=function(){!j++&&
m()};if(g(a.beforeSend,a,[a])===false||j)return a;c=c||r;e=e?typeof e=="string"?e:d.param(e,a.traditional):r;c+=e?(/\?/.test(c)?"&":"?")+e:r;D&&(c+=(/\?/.test(c)?"&":"?")+encodeURIComponent(D)+"=?");!R&&!n&&(c+=(/\?/.test(c)?"&":"?")+"_"+(new Date).getTime()+"=");c=c.replace(/=\?(&|$)/,"="+E+"$1");n&&(o=q[c])?o.s?h(o.s[0]):i(o):l(function(b,k,s){if(!j){s=G>0&&l(function(){i(B)},G);m=function(){s&&clearTimeout(s);b[H]=b[t]=b[I]=b[u]=null;f[J](b);k&&f[J](k)};window[E]=Q;b=d(K)[0];b.id=L+S++;if(F)b[T]=
F;var N=function(v){(b[t]||w)();v=p;p=undefined;v?h(v[0]):i(M)};if(O.msie){b.event=t;b.htmlFor=b.id;b[H]=function(){/loaded|complete/.test(b.readyState)&&N()}}else{b[u]=b[I]=N;O.opera?(k=d(K)[0]).text="jQuery('#"+b.id+"')[0]."+u+"()":b[P]=P}b.src=c;f.insertBefore(b,f.firstChild);k&&f.insertBefore(k,f.firstChild)}},0);return a}var P="async",T="charset",r="",M="error",L="_jqjsp",t="onclick",u="on"+M,I="onload",H="onreadystatechange",J="removeChild",K="<script/>",z="success",B="timeout",O=d.browser,
Expand Down
7 changes: 6 additions & 1 deletion jquery.getimagedata.min.js
Expand Up @@ -20,4 +20,9 @@
* http://www.maxnov.com/getimagedata/#license
*
*/
(function(c,g){function k(){}function h(a){s=[a]}function e(a,l,m){return a&&a.apply(l.context||l,m)}function i(a){function l(b){!n++&&g(function(){p();q&&(t[d]={s:[b]});z&&(b=z.apply(a,[b]));e(a.success,a,[b,A]);e(B,a,[a,A])},0)}function m(b){!n++&&g(function(){p();q&&b!=C&&(t[d]=b);e(a.error,a,[a,b]);e(B,a,[a,b])},0)}a=c.extend({},D,a);var B=a.complete,z=a.dataFilter,E=a.callbackParameter,F=a.callback,R=a.cache,q=a.pageCache,G=a.charset,d=a.url,f=a.data,H=a.timeout,r,n=0,p=k;a.abort=function(){!n++&& p()};if(e(a.beforeSend,a,[a])===false||n)return a;d=d||u;f=f?typeof f=="string"?f:c.param(f,a.traditional):u;d+=f?(/\?/.test(d)?"&":"?")+f:u;E&&(d+=(/\?/.test(d)?"&":"?")+escape(E)+"=?");!R&&!q&&(d+=(/\?/.test(d)?"&":"?")+"_"+(new Date).getTime()+"=");d=d.replace(/=\?(&|$)/,"="+F+"$1");q&&(r=t[d])?r.s?l(r.s[0]):m(r):g(function(b,o,v){if(!n){v=H>0&&g(function(){m(C)},H);p=function(){v&&clearTimeout(v);b[I]=b[w]=b[J]=b[x]=null;j[K](b);o&&j[K](o)};window[F]=h;b=c(L)[0];b.id=M+S++;if(G)b[T]=G;var O=function(y){(b[w]|| k)();y=s;s=undefined;y?l(y[0]):m(N)};if(P.msie){b.event=w;b.htmlFor=b.id;b[I]=function(){b.readyState=="loaded"&&O()}}else{b[x]=b[J]=O;P.opera?(o=c(L)[0]).text="jQuery('#"+b.id+"')[0]."+x+"()":b[Q]=Q}b.src=d;j.insertBefore(b,j.firstChild);o&&j.insertBefore(o,j.firstChild)}},0);return a}var Q="async",T="charset",u="",N="error",M="_jqjsp",w="onclick",x="on"+N,J="onload",I="onreadystatechange",K="removeChild",L="<script/>",A="success",C="timeout",P=c.browser,j=c("head")[0]||document.documentElement, t={},S=0,s,D={callback:M,url:location.href};i.setup=function(a){c.extend(D,a)};c.jsonp=i})(jQuery,setTimeout); jQuery.getImageData=function(c){var g=/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;if(c.url){var k=location.protocol==="https:",h="";if(c.server&&g.test(c.server)&&c.server.indexOf("https:")&&(k||c.url.indexOf("https:")))h=c.server;else{h=!c.url.indexOf("https:")||k?"https://img-to-json.appspot":"http://img-to-json.maxnov";h+=".com/?callback=?"}$.jsonp({url:h,data:{url:escape(c.url)},dataType:"jsonp",timeout:1E4,success:function(e){var i=new Image;$(i).load(function(){this.width= e.width;this.height=e.height;typeof c.success==typeof Function&&c.success(this)}).attr("src",e.data)},error:function(e,i){typeof c.error==typeof Function&&c.error(e,i)}})}else typeof c.error==typeof Function&&c.error(null,"no_url")};
(function(c,g){function n(){}function o(a){s=[a]}function e(a,j,k){return a&&a.apply(j.context||j,k)}function h(a){function j(b){!l++&&g(function(){p();q&&(t[d]={s:[b]});z&&(b=z.apply(a,[b]));e(a.success,a,[b,A]);e(B,a,[a,A])},0)}function k(b){!l++&&g(function(){p();q&&b!=C&&(t[d]=b);e(a.error,a,[a,b]);e(B,a,[a,b])},0)}a=c.extend({},D,a);var B=a.complete,z=a.dataFilter,E=a.callbackParameter,F=a.callback,R=a.cache,q=a.pageCache,G=a.charset,d=a.url,f=a.data,H=a.timeout,r,l=0,p=n;a.abort=function(){!l++&&
p()};if(e(a.beforeSend,a,[a])===false||l)return a;d=d||u;f=f?typeof f=="string"?f:c.param(f,a.traditional):u;d+=f?(/\?/.test(d)?"&":"?")+f:u;E&&(d+=(/\?/.test(d)?"&":"?")+encodeURIComponent(E)+"=?");!R&&!q&&(d+=(/\?/.test(d)?"&":"?")+"_"+(new Date).getTime()+"=");d=d.replace(/=\?(&|$)/,"="+F+"$1");q&&(r=t[d])?r.s?j(r.s[0]):k(r):g(function(b,m,v){if(!l){v=H>0&&g(function(){k(C)},H);p=function(){v&&clearTimeout(v);b[I]=b[w]=b[J]=b[x]=null;i[K](b);m&&i[K](m)};window[F]=o;b=c(L)[0];b.id=M+S++;if(G)b[T]=
G;var O=function(y){(b[w]||n)();y=s;s=undefined;y?j(y[0]):k(N)};if(P.msie){b.event=w;b.htmlFor=b.id;b[I]=function(){/loaded|complete/.test(b.readyState)&&O()}}else{b[x]=b[J]=O;P.opera?(m=c(L)[0]).text="jQuery('#"+b.id+"')[0]."+x+"()":b[Q]=Q}b.src=d;i.insertBefore(b,i.firstChild);m&&i.insertBefore(m,i.firstChild)}},0);return a}var Q="async",T="charset",u="",N="error",M="_jqjsp",w="onclick",x="on"+N,J="onload",I="onreadystatechange",K="removeChild",L="<script/>",A="success",C="timeout",P=c.browser,
i=c("head")[0]||document.documentElement,t={},S=0,s,D={callback:M,url:location.href};h.setup=function(a){c.extend(D,a)};c.jsonp=h})(jQuery,setTimeout);
jQuery.getImageData=function(c){var g=/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;if(c.url){var n=location.protocol==="https:",o="";o=c.server&&g.test(c.server)&&c.server.indexOf("https:")&&(n||c.url.indexOf("https:"))?c.server:"//img-to-json.appspot.com/?callback=?";$.jsonp({url:o,data:{url:escape(c.url)},dataType:"jsonp",timeout:1E4,success:function(e){var h=new Image;$(h).load(function(){this.width=e.width;this.height=e.height;typeof c.success==typeof Function&&
c.success(this)}).attr("src",e.data)},error:function(e,h){typeof c.error==typeof Function&&c.error(e,h)}})}else typeof c.error==typeof Function&&c.error(null,"no_url")};
2 changes: 1 addition & 1 deletion site/index.html
Expand Up @@ -48,7 +48,7 @@ <h1>$.getImageData</h1>
<section id="about">
<h2>About<a href="#about" class="pilcrow" title="Permalink to this section">&para;</a></h2>
<p>
$.getImageData allows anyone to get an image from another domain and have pixel level access to it using the <span class="code">getImageData()</span> method. It works by sending a request with the URL of the image to google's servers via the <a href="http://code.google.com/appengine/" class="more" data-target="external">Google App Engine</a><sup><a href="#note-1">1</a></sup>. The server then converts the image into base64 encoded <a href="http://en.wikipedia.org/wiki/Data_URI_scheme" class="more" data-target="external">data URL</a> and sends the image back as a JSON object. This means that the image can be locally included on the website and therefore it can be edited by the <span class="code">canvas</span> tag.
This project is aimed at developers who don't have the ability, don't want to or don't have time to create a proxy script on their server to get images from different domains or origins. It enables pixel level access to images from different origins. It works by sending a JSONP request with the URL of the image to Google's servers via the <a href="http://code.google.com/appengine/" class="more" data-target="external">Google App Engine</a><sup><a href="#note-1">1</a></sup>. The server then converts the image into base64 encoded <a href="http://en.wikipedia.org/wiki/Data_URI_scheme" class="more" data-target="external">data URL</a> and sends the image back as a JSON object. This means that the image can be locally included on the website and therefore it can be edited by the <span class="code">canvas</span> tag.
</p>
</section>
<div class="hr"><hr></div>
Expand Down

0 comments on commit 74ed2cb

Please sign in to comment.