#!/usr/bin/perl # pcg@goof.com # this is not totally serious... use Gimp; use Gimp::Fu; use Gimp::UI; use Fcntl; sub encode_base64($) { my $res = substr pack ("u", $_[0]), 1; $res =~ s/\n.//mg; $res =~ tr|` -_|AA-Za-z0-9+/|; #` # syntax-hiliting in emacs kanns nicht my $padding = (3 - length($_[0]) % 3) % 3; $res =~ s/.{$padding}$/'=' x $padding/e if $padding; $res; } register "file_dataurl_save", "Saves the image as many small tiles using data:-urls", "=pod", "Marc Lehmann", "Marc Lehmann ", "1999-11-20", "/DATAURL", "*", [ [PF_SPINNER, "tile_x", "tile width", 32, [0, 8192, 1, 10]], [PF_SPINNER, "tile_y", "tile height", 32, [0, 8192, 1, 10]], [PF_RADIO, "filetype", "underlying file type", 0, [GIF => 0, JFIF => 1, PNG => 2]], ], sub { my($img,$drawable,$filename,$filename2,$tx,$ty,$type) = @_; my($new_img,$new_drawable); my $max; my $export = Gimp::UI::export_image ($new_img=$img, $new_drawable=$drawable, "DATAURL", $type==0 ? CAN_HANDLE_INDEXED|CAN_HANDLE_ALPHA : $type==1 ? CAN_HANDLE_RGB|CAN_HANDLE_GRAY : $type==2 ? CAN_HANDLE_RGB|CAN_HANDLE_GRAY|CAN_HANDLE_INDEXED : 0 ); die __"export failed" if $export == EXPORT_CANCEL; my ($w,$h) = ($new_drawable->width, $new_drawable->height); my $tmp = Gimp->temp_name(".img~"); sysopen FILE,$filename,O_CREAT|O_TRUNC|O_WRONLY or die __"Unable to open '$filename' for writing: $!\n"; print FILE "\n"; init Progress __"Saving '$filename' as DATAURL..."; my $media = $type==0 ? "gif" : $type==1 ? "jpeg" : $type==2 ? "png" : ""; print FILE ""; for(my $y=0; $y<$h; $y+=$ty) { my $wy = $h-$y < $ty ? $h-$y : $ty; print FILE ""; for(my $x=0; $x<$w; $x+=$tx) { my $wx = $w-$x < $tx ? $w-$x : $tx; my $img = $new_img->channel_ops_duplicate; $img->crop($wx,$wy,$x,$y); ($img->get_layers)[0]->file_gif_save (($tmp)x2, 0, 0, 0, 0) if $type==0; ($img->get_layers)[0]->file_jpeg_save (($tmp)x2, 0.7, 0, 1, 0, "", 0, 1, 0, 0) if $type==1; ($img->get_layers)[0]->file_png_save (($tmp)x2, 0, 1, 9) if $type==2; $img->delete; my $data = do { local(*TEMP,$/); open TEMP, "<$tmp" or die __"Unable to read temporary image tile $tmp: $!"; ; }; unlink $tmp; $url = "data:image/$media;base64,".(encode_base64 $data); $max = length($url) if length($url) > $max; print FILE "
"; update Progress (($y*$w+$x*$ty)/($w*$h)); } } print FILE "
\n"; print FILE "\n"; close FILE; warn __"url size is too large ($max > 1024)\n" if $max > 1024; $new_img->delete if $export == EXPORT_EXPORT; (); }; Gimp::on_query { Gimp->register_save_handler("file_dataurl_save", "dataurl", ""); }; exit main; =head1 DATAURL FILE FORMAT After reading rfc2397, which describes the C url scheme, I got the idea of embedding a normal image into a html document, without resorting to external files. This is acomplished by embedding small tiles of the image directly into data:-urls. Since attribute values are by default limited to 1024 bytes this limits the size of a tile to approximately 34x34 pixels (gif compression). However, since rfc2397 is only a proposed standard, you might want to use much larger tile sizes (upto the image size), since most browsers generally do not care for the url length. Browser compatibility list (send more results to pcg@goof.com ;) Netscape 3.x displays broken image icons Netscape 4.x works on some configurations (communicator!), not on others (navigator!) Lynx displays the base64 code as text :( MSIE 4 thousands of error messages in dialog boxes ;-> MSIE 5 shows broken image icon =for nobody yosh: cvs.gimp.org I mean which "removed debugging crap" one yosh: or did you mean the debugging code in the Perl-Server? yah debian's perl whines about using -D since it's not compiled with -DDEBUGGING yosh: ah.. I it was ebing queried.. yosh: yeah, but you did not see the that required people to press enter in colorhtml ;) anybody here with netscape 3.0? or msie 5.0? or any other graphical browser? schmorp: it was in innerbevel, you must've fixed colorhtml before I had a chance to update schmorp: ns3.0 here maswan: could you try something out? -> http://www.goof.com/pcg/marc/dataurl.html maswan: what do you see, especially below "dataurl filter" yosh: at least ;-> *** Joins: Nether [lealanko@myntti.helsinki.fi] has joined #gimp *** Mode change for #gimp by XachBot: +o Nether schmorp: slooow.... schmorp, evil thingie.. I'm loading it in win98/ie on a p60 8) *** Nether [lealanko@myntti.helsinki.fi] is now known as Neth_ZzZ that html page contains no external links, i.e. all images are embedded and yes, the colour-changing is bogging down most browsers i want to find out how many browsers support the data: url I get a gazillion of [x] broken image thingies at the bottom half schmorp: embedded? I got _lots_ of broken external images on the bottom half stric: which browser? http://www.goof.com/pcg/marc/data:image/gif;base64, R0lGODlhIgAiAOMAAA8UFDo/OGt9eJecj722oFxfVIl/a+vSrn5oTtiyg7qfe6SGZUlgX+LCliElIdCldCwAAAAAIgAiAAAE/vAd9dajKlV6FddY9TTd9ZzmSWkPi2quYiUsiJ4uXd+6i/e3Vk/XQpGMRVxj9 1omnE/n8nhqUGmv2lMnXY6EWBc0rNxah8IRjQQbeouw0dhKT5+562Cevu1BpWtcPy1WYHdmT2psXn1DjYF8fmdnhJCIB4VTmlyRdE5ggZhTnIFrXX6SDaKPZpN4XAd+sXV8f1GagFmmd7ZWmKaNo5ZDs1GoTh k0sW5dkcGtJIeeuJ6kt7Nny7vTzXyiq2zGo7VS4NSqrdiIU8voJKLV04hypa5mB/DOw+K3qt147JQBfPLLU0Fh5IxhqdTHXh schmorp, win98/ie (4? 5?) maswan: ok, so ns3.0 does not support it stric: i don't know how to find out ;9 schmorp, 5 appearantly... ok... ns3.0 and msie5 show broken image icons. msie displays one dialog box per link (evil) lynx errornously displays the base64 data haha so only netscape 4 displays it correctly that is too evil tried mozilla? *** Quits: _vicious_:#gimp [~jirka@dt062nd1.san.rr.com] (GEGL!) yosh: mozilla does not run, did not run and will probably never run yosh: everytime I come here and somebody talks about mozilla he says "well, it is quite cool" yosh: everytime _I_ try it ends in an endless loop after 5 seconds or so heh you must be broken then yosh: but I guess mozilla will do it as well schmorp: I get broken images with NS 4.7 yosh: really? thats cool... it works with ns 4.06 (here) and ns 4.6 (my friend) yosh: on linux? yes yosh: i wonder why they removed support for it.. I get broken stuff with 4.51 *** TomR^AwaY [~tomr@judas.aceldama.com] is now known as Tommer hey Tommer Works for me on NS 4.71 on LinuxPPC Hullo yosh tommer: really? dataurl is very cute, schmorp Yup * yosh tries mozilla something must be broken... 4.06 yes, 4.51 no, 4.6 yes, 4.7 no, 4.71 yes... I see a pattern... Oh, you mean the ($ver*100)%2 == (dataurl works) relation? Oh wait, 4.6 doesn't match that. * maswan tries ns4.61 on aix oh, that 4.6 is probably measurement error schmorp, for the next trick, do :) haha hmm... it works with 4.51 here.... eeek. how about *** Quits: tigert:#gimp [tigert@fun112.koivukyla.hoas.fi] (Ping timeout: 660 seconds) tommer: hmm... now that would be cool... it would not even need base64 encoding, and would probably work even with lynx this one is sloow for some reason. hmm *** Topic change by sjburges on #gimp: its abuse html night schmorp: yes, as long as you used " everywhere you'd be fine :) maswan: "aix".... could it be that clinton only knows of the internet from al gore? schmorp, low mhz combined with netscape on 24bpp hmm.. or ssh. oops. :) "reduce the gap between rich and poor by giving everyone internet access" Does anyone have red+blue 3D glasses handy? yay clinton. you da man schmorp: works on this one stric: but since netscaope can't display colour icons in 24bpp it should be much faster ;-> maswan: thanks ;) schmorp, I haven't had that problem on non-linux hmm.. it is estimating speed at 2k/s tommer: the problem is that urls are max. 1k in size schmorp, I correct that to aix/irix/solaris tommer: but on the browsers that support it, dataurls can be much longer which means much time for that file schmorp: can't you specify encoding=base64 _and_ encoding=gzip? hum, mozilla sucks ;) tommer: i can't specify an encoding per se. if, then it must be a netscape extension tommer: maybe image/gzip-jpg or something.... schmorp: oh, so you can only specify a content type, not an encoding? I was guessing about the encoding thing. * maswan tries irix netscape 4.something 4.61 here too tommer: the base64 is specified as ";base64", so it is somethign special tommer: but since I can specify charset=xxx, maybe I can also add encoding=gzip... works that too tommer: BUT... if I can use gzip, then I cna use long urls. Then I can use png, and then i don't need gzip schmorp: just think, you could put a whole site in one page with framesets and dataurl :) yosh: mozilla sucks, yes, but does it display it? How are gzip and long urls related, schmorp? schmorp: it segfaults ;) tommer: hmm... I'm thinking images only... tommer: if you think text then encoding=gzip makes sense tommer: I also haven'T tried wether these urls work in frameset and normal anchor elements but actually, the colorhtml filter is much more portable yeah, it just takes aching long to render and scroll schmorp: how about ? yes... maybe when this type of encapsulation becomes more often used... at least we can claim that msie is not rfc2397 compatible xachbot, seen dv -XachBot:#gimp- I last saw dv (veillard@home5.inrialpes.fr) 7d 13h 17m ago [quit: (xchat exiting..)] schmorp, and who will care? 8) tommer: that might even be a useful usage!! *** Joins: JohnP [me2@d027.pnj.early.com] has joined #gimp *** Mode change for #gimp by XachBot: +o JohnP Hey! schmorp: but lowsrc is an evil Netscape invention :) *** Joins: tigert [~tigert@fun112.koivukyla.hoas.fi] has joined #gimp *** Mode change for #gimp by Wilber: +o tigert tigpoo tigert! schmorp: tommer: does the lowsrc image have to have the same size/resolution? Hmm, does and such work? hmm.. sleep. now. schmorp: lowsrc _should_ have the same size/resolution. if you specify width and height then the lowsrc will be resized of course. tommer: .... and since it's netscaoe only we do not need to care schmorp: yes, if you're abusing HTML you may as well go whole hog. tommer: hey, it's a "proposed standard" ;) heh A nice thing about NS on the Mac is that if you shrink a mono image then it renders it antialiased :) Tommer> Pull out your red+blue 3D glasses and go to: http://www.aceldama.com/~tomr/wx/tomrcam-3d-2.jpg yosh: rfc2397 "data: url scheme" *** Joins: jlb [~jlbec@slip-32-101-161-237.nc.us.prserv.net] has joined #gimp *** Mode change for #gimp by XachBot: +o jlb tommer: looks flashy (no 3d cam here ;) ok, bye all! ttyl schmorp sjburges: have a nice time with your new g/f! interesting schmorp: you need 3D glasses ok, food *** yosh [manish@graft.XCF.Berkeley.EDU] is now known as yosh_food tommer: if you do some weird things with urls, drop me a note ;-> tommer: ah, yes, _glasses_ i meant