Skip to content

Instantly share code, notes, and snippets.

@ne1uno
Last active September 23, 2022 13:36
Show Gist options
  • Save ne1uno/74efc2bda96a662dbf7d8858a60cfcf1 to your computer and use it in GitHub Desktop.
Save ne1uno/74efc2bda96a662dbf7d8858a60cfcf1 to your computer and use it in GitHub Desktop.
base 64 & image utility with red-lang
small utility to work with base 64 and custom red-lang embedded png images
bits of code from anywhere,
screenshot
https://usercontent.irccloud-cdn.com/file/2zLaOKXj/b64-png-screenshot.jpg
still haven't solved how to encode base 64 png, but decoding works
could decode directly from file? might be a workaround for now... nope
user interface has some anomalies, likely caused by ne1, may or may not fix.
smaller test script in comments at end of this script.
copy/paste icons fall back to drawing C/P vrs image files
could easily make them small buttons, just ui eye candy from 32x32 tango set
probably embed so can post single file gist. tooltip a little wonky
tango or other icon url for copy/paste in the first revisions
***************** ***************** *****************
can put two png icons [edit-copy.png edit-paste.png] in same directory
attached to this gist or find in icon set
assuming add images to a gist works
cfg context has some editable font & color options. later select themes
for tests: need newer ../tests/testing.rd from ne1 and enable test block
assumes tabs 4 space, ASCII English string, un-tested otherwise
later may need redCV to optimize & resize images
***************** *********************** ***********
using compose on view layout adds complication for words in local scope
(first [localword]) or needing to guard parens with to-paren [(runtime parens)]
broken out of one of my kitchen sink apps as standalone tab
from minimal gui tabbed window template with basic config
Red [
Title: "base 64 png images"
Author: "ne1 et al"
License: "fair use bits of code from anywhere"
Date: "~2022/9-12"
version: "opus:s2022917p12"
icon: freni.ico ;may or may not show interpreted
rights: "MITish"
productname: "built with Full Stack Tech from red-lang.org"
Needs: 'View
]
dev+: no
test+: no
;add -encap? set yes if encapped so compiled/interpreted? switches work at least
-encap?: no
; need in color init, was inlined in help popup now a func again
split-lines: func [{
split s on newline removing leading indentation & nl unless keep
maybe later
optionally don't remove leading tabs of s/1 '_ count
optionally split & sub-split on char series or parse rule, incl ""
}
s [series!]
/toinsert si [series!] ;"^M " for help, win area newline join/with
; /split-on sc [char! series!] "default newline"
; /sub-split ss [char! series!] "further split item"
/keep-indent "this keeps leading indent, removed by default."
/keep-blanks "keep-blank lines with just space or tab but emptied" ; keep-nl sub-split lines by some string ""= explode
/local res lines l u
][
unless toinsert [si: ""]
lines: split s charset "^/" ;^M too? is this cross platform? read/lines faster?
;assumes string with newlines
res: copy [] ;could allocate size
;want to use parse but I'm not sure how to make it reliable with optional
; hurting my brain. was much simpler before keep-blanks
; seems to be an extra trailing blank line if /keep-blanks
; remove up s/1 tocount '_ adds one more complication + space vrs tab
; might also just count blanks but tricky if editor removes trailing
u: either all [not keep-indent lines/1/1 = #"_"] [take lines][0]
; need to only reduce by amount of indent
;just convert tab to 4space
;if u > 0 [u: probe to-integer (to-paren [(length? u)]) / 3.2] ;if was tabs
if string! = type? u [
;u: probe to-integer (length? u) / 3.2 ;if was tabs
count: 0
foreach x u [
case [
x = #"_" [count: count + 1]
'true [break]
]
]
;u: probe to-integer (count / 4)
u: count ;tab/space accounted for at skip over indent
]
; as used in help, without keep options
;
; foreach x s [
; trim/tail x ;keep trailing space?
; take/part x u /does 0 take nothing?
; if toinsert [insert x si]
; ]
; refactor split-lines from mylib which stripped all leading indent
foreach l lines [
either keep-indent [
either keep-blanks [
append res l ;unchanged whatever blank or not
][
;also need to process u here
if not any [(length? l) = 0 (trim/head copy l) = ""][
append res l ; only if not blank indent or not could be option
]
]
][
;don't keep indent, but also watch trim only leading indent.
;holy f*k, very greedy even just /head if use /with it's like /all
;print ["l=" l]
;trim/head l ;space/tab default?
; looks may be just space? destructive to l
;probe l
either 0 = length? l [
if keep-blanks [
append res l
]
][
;not ideal, should just change indent tabs
; if u > 0 [replace/all/deep l "^-" " "]
; take/part l u
; only remove u many space or tab or 0 as '_
;might take extra in mixed tab/space
; can't take half a tab, doesn't add space back
if dev+ [sm: form reduce [u length? l l]]
count: 0
while [count < u][
case [
l/1 = #" " [count: count + 1]
l/1 = #"^-" [count: count + 4]
'true [break]
]
l: next l
]
if dev+ [probe reduce [sm newline u count index? l length? l l]]
append res l
]
]
;if all [toinsert 0 < length? last res] [insert last res si]
if toinsert [insert last res si]
]
return res
]
#define____cnames___ ;geany sidebar bookmarker
;TBD
;make color list just solorized and red-colors,
; object/block vrs map easier to use in view
; @dander [solarized color palette gist](https://gist.github.com/dander/a7546f4ee56a0192ee97ab0dbca497db)
cnames-hexkeys: make block! 95 ;TBD
init-cnames: function [
][
alpha: 0
;finish /sub-split
;solorized @dander?
foreach c split-lines/sub-split {
-Sol-Base03 002b36
-Sol-Base02 073642
-Sol-Base01 586e75
-Sol-Base00 657b83
-Sol-Base0 839496
-Sol-Base1 93a1a1
-Sol-Base2 eee8d5
-Sol-Base3 fdf6e3
-Sol-Yellow b58900
-Sol-Orange cb4b16
-Sol-Red dc322f
-Sol-Magenta d33682
-Sol-Violet 6c71c4
-Sol-Blue 268bd2
-Sol-Cyan 2aa198
-Sol-Green 859900
}[
hname: split c charset " ^-"
; probe hname
;instead of map could set names, check any conflict with existing colors
;lower casing everything. should hyphenate words
; Chocolate Chartreuse conflict with hex literal Nh
;need to-word to-issue or check actually created word
;to-issue trim fails needs series needed paren??
r: copy/part hname/2 2
g: copy/part at hname/2 3 2
b: copy/part at hname/2 5 2
rgb: make tuple! reduce [
to-integer debase/base r 16
to-integer debase/base g 16
to-integer debase/base b 16
alpha
]
;print [r g b rgb]
;make raw hex into whatever color tupple.
;might want to preserve the hue order?
cnames/(to-word to-issue hname/1): rgb
; print ['bug 2 hname/1]
append cnames-huekeys to-word to-issue hname/1
;append/only cnames-hexkeys reduce [rgb-to-hex/base16 rgb (to-lit-word hname/1)]
;don't add -Sol, special case, shouldn't be available as nearest
;probably not optimal FIXME
;
if "-Sol-" <> copy/part hname/1 5 [
;probe hname/1
append/only cnames-hexkeys reduce [rgb-to-hsv/base16 rgb (to-lit-word to-issue hname/1)]
]
]
acolors: [aqua beige black blue brick brown coal coffee crimson cyan forest glass
gold gray green ivory khaki leaf linen magenta maroon mint navy oldrab
olive orange papaya pewter pink purple reblue rebolor red sienna silver
sky snow tanned teal transparent violet water wheat white yellow]
forall acolors [
;if none? cnames/(acolors/1) [ oldmap
if not find cnames (acolors/1) [ ;newmap
;cnames/(to-word :acolors/1): get acolors/1 ; to-word :word and just word works 064 not newmap?
cnames/(to-set-word to-issue acolors/1): get acolors/1 ; no diff
append cnames-huekeys acolors/1
; add missing colors
;append/only cnames-hexkeys reduce [rgb-to-hex/base16 get acolors/1 to-lit-word acolors/1]
append/only cnames-hexkeys reduce [rgb-to-hsv/base16 get acolors/1 to-lit-word acolors/1]
]
]
;check if all these are web safe and work in screen recorders
;seems like an unreliable sort,
;; sort/compare cnames-hexkeys func [a b] [
;; (ax: rgb-to-hex cnames/:a) < (bx: rgb-to-hex cnames/:b) [-1] [either ax > bx [1] [0]]
;; ]
; also, woops needed to store kex keys directly index to key in map or huelist...
;otherwise would need to constantly do rgb-to-hex to know what they are
sort cnames-hexkeys
]
; probe init-cnames ;convert to first use of map calls init somehow
; cfg context on-change on-access
;
; print cnames/wheat ; copied from linux colors make map
; halt
; from ../testing.rd, avoiding include
; mask percent for R2
;
; gist/toomasv/form-to.red 2019-0-13
; ne1 22/1 recent only shows fractional
; added workaround join/with but think fixed org, forget details
; did I comment on @toomasv gist or got fixed?
; should accept precision 0 to truncate
form-to-tv: func ["Form number to a given floating-point precision"
number [number!] "Number to be formed"
precision [integer!] "Decimal places (positive integer)"
/local pcnt?
][
if precision < 1 [cause-error 'user 'message "`precision` has to be positive integer!"]
; either off [
if percent? number [pcnt?: yes number: 100.0 * to-float number]
number: form round/to number 1.0 / power 10 precision
;recent find or pad changed? older returned head?
number: pad/with find/tail number dot precision #"0"
if pcnt? [append number #"%"]
; ][
; ;needs join/with *workaround*
; ; number: pad/with find/tail form number dot precision #"0"
; numberb: split form number dot
; if 2 = length? numberb [
; number: form to-float join/with [numberb/1 copy/part numberb/2 precision] dot
; ]
; ]
head number
]
; <toomasv> thousands posted on gitter
;ne1 add option. form-to if precision
;
commafy-tv: func ["adds coma every 3rd digit"
num [number! string!]
/coma sep "default ,"
/precision places "call form-to"
/local int frac
][
sep: either coma [sep][","]
if precision [num: form-to-tv to-float num places] ;adds maybe trailing zeros
set [int frac] split form num dot
parse reverse int [any [3 skip [end | insert sep]]]
num: reverse int
if frac [repend num [dot frac]]
num
]
#define___calc_Kib__
;could have it auto select magnitute if > multiplier
;everything in Kib for now
; 496 on disk 5,859,000 Kib looks wrong
calc-Kib: func [ "call modified local commafy w/precision appends Si units"
num [number! string!]
/Mib "default /1024 Kib, Mib /1.024e3 or something "
/Gib "Gib /1.024e6"
/precision places "default 3"
][
if string! = type? num [attempt [num: to-float num]] ;load?
if any [none? num num = ""] [return ""]
; Mib Gib both would be user error
ib: copy case [
Mib [" Mib"]
Gib [" Gib"]
'true [" Kib"]
]
Kib: case [
Mib [1024.0 * 1e3]
Gib [1024.0 * 1e6]
'true [1024.0]
]
places: case [
precision [places]
'true [3]
]
x: num / Kib
rejoin [commafy-tv/precision x places ib] ;is /1024 Mib MB or Kib KB
]
; need padding and zero places
; cfg: make map! [] ;map paths problematic in some view
cfg: context [ ;context paths work in more places than map keys in view
win: none
init-pos: 120x10 ;outside win10 narrow side taskbar
; smaller laptop screens <700 with higher dpi/font even less
; e530 ok ~720, L512 needs <x670 to have comfortable margins
; both have 15 inch screens but L15 slightly less y resolution
;
;. need to have 2nd row of buttons and keep area height less
; might have short/tall on area, sm/med/lg on fonts from cfg
; width of 1024x typical these days but some still have less
window-size: 650x670
new-window: false
img-file-path: "/C/img/JustUpload/some.png"
icon-dir: "./"
;make dark/light set
;use different style setup or compose so can set everything
; red white transparent gray aqua beige black blue brick brown coal
; coffee crimson cyan forest gold green ivory khaki leaf linen magenta
; maroon mint navy oldrab olive orange papaya pewter pink purple reblue
; rebolor sienna silver sky snow tanned teal violet water wheat yello
; yellow glass
; color-go color-stop color-pause color-disabled color-ready
; > mint ;#648874
; == 100.136.116
;early libs I was adding because didn't look like spearmint or peppermint
; but now it doesn't even look green? more blue, was my monitor bad?
; >> nmint: mint + 0.25.75
; view [base 100x200 nmint base 100x200 mint]
; still needs a tweak.
; nmint: mint + 0.15.15 ;lighter tward spearmint or darker toward peppermint
; view [base 100x200 nmint base 100x200 mint]
; do a hue sort and complement color match html for just red colors
;add solorized option
bg-color: tanned ;
bd-color: beige ;backdrop
fg-color: coal
ttip-color: yello + 5.30.2
fnt: make font! [name: "Menlo" size: 12] ;
] ;these might get set on init and changed via cfg-file and saved,
;not sure anytime changed or just on exit
;is it map or any path has some problems using in view?
; cfg/bg-color worked but not cfg/fnt
ttfont: make font! [ ;tooltips
name: "Consolas"
size: 9
color: cfg/fg-color
]
;RSN
; must be selected ahead of cfg or better, include in cfg
;will have cfg and mode button to test different themes RSN.
; not sure how to discover users default color theme. w/o red/system
use-theme: pick ['light 'dark 'solorize-light 'solorize-dark 'user] 3 ;12345
; Dawn Dusk Tropic Emerald Sand Rust Orchid Ocean Ash Midnight high-contrast
; https://ethanschoonover.com/solarized/ find official solorize-light solorize-dark
; if use-theme = 'user [
; c-fg-hi: cnames/White
; c-fg: cnames/Brown ; button and area text foreground color
; c-fg-lo: cnames/white
; c-bg-hi: cnames/mint
; c-bg: cnames/teal ; gui background color
; c-bg-lo: cnames/Green ;gui area/text bg
; c-red: cnames/Pink ;near iso-red, shape colors red green blue
; c-green: cnames/Green
; c-blue: cnames/Gray ;near iso-blue
; tile-on: cnames/wheat ; want neutral colors selected color
; tile-off: cnames/ivory ; that don't conflict with shapes tile background
; ]
; if use-theme = 'solorize-light [
; ;; Solorized light not pure solorized base00-03 very confusing names
; c-fg-hi: cnames/-Sol-base01
; c-fg: cnames/-Sol-base00
; c-fg-lo: cnames/-Sol-base1
; c-bg-hi: cnames/-Sol-base2
; c-bg: cnames/-Sol-base3
; c-bg-lo: cnames/Linen ;-Sol-base1 too dark. bug/wish for solorized
; c-red: cnames/-Sol-red
; c-green: cnames/-Sol-green
; c-blue: cnames/-Sol-blue
; tile-on: cnames/Wheat ;;-Sol-base2 not dark enough base1 too dark
; tile-off: cnames/-Sol-base3 ;Cornsilk dark pale GoldenRod Wheat Linen
; ]
; if use-theme = 'solorize-dark [
; ;; Solorized dark, someone into dark themes will have to tweak these
; c-fg-hi: cnames/-Sol-base1
; c-fg: cnames/-Sol-base0
; c-fg-lo: cnames/-Sol-base01
; c-bg-hi: cnames/-Sol-base02
; c-bg: cnames/-Sol-base03
; c-bg-lo: cnames/-Sol-base1 ;?
; c-red: cnames/-Sol-red
; c-green: cnames/-Sol-green
; c-blue: cnames/-Sol-blue
; tile-on: cnames/-Sol-base00
; tile-off: cnames/-Sol-yellow
; ]
; if use-theme = 'dark [
; ;; Autum dark
; c-fg-hi: cnames/gold
; c-fg: cnames/Bisque
; c-fg-lo: cnames/whitesmoke
; c-bg-hi: cnames/water
; c-bg: cnames/gray
; c-bg-lo: cnames/Gainsboro
; c-red: cnames/tomato
; c-green: cnames/forestgreen
; c-blue: cnames/royalblue
; tile-on: cnames/Sienna
; tile-off: cnames/SaddleBrown
; ]
; if use-theme = 'light [
; ;; Ocean light
; c-fg-hi: cnames/AntiqueWhite
; c-fg: cnames/SaddleBrown ; button and area text foreground color
; c-fg-lo: cnames/white
; c-bg-hi: cnames/mintcream
; c-bg: cnames/sky ; gui background color
; c-bg-lo: cnames/PaleGreen ;gui area/text bg
; c-red: cnames/LightPink ;near iso-red, shape colors red green blue
; c-green: cnames/LightGreen
; c-blue: cnames/LightSlateGray ;near iso-blue
; tile-on: cnames/paleGoldenRod ; want neutral colors selected color
; tile-off: cnames/ivory ; that don't conflict with shapes tile background
; ;make selected on color slightly lighter or darker, not so close you won't know what's selected
; ]
; cfgfont: cfg/fnt ;can't use path in style? or any word?
bg-color: cfg/bg-color ;style and a few places don't like paths
ttip-color: cfg/ttip-color
img-file-path: cfg/img-file-path
; from Arnold van Hofwegen 2017 gist?
;
; all errors to ne1, modified for use
; relative event ofset at window 0x0, status onmouseover
; position each tip where you want it, not really automatic as it could be
; need get resize to update extra/offset
show-tooltip: func [
val
evt
tip
][
;print [val tip/offset evt/offset evt]
tip/visible?: not val
;try to store org offset to restore on out, breaks on resize, needs work
;
either none? tip/extra [
;print ["******extra " tip/offset tip/extra]
tip/extra: make map! reduce ['offset tip/offset ]
][
;print ["******either " tip/offset tip/extra]
if not tip/visible? [tip/offset: tip/extra/offset]
]
;needs work to make sure is in a readable position
;tip/offset: tip/extra/offset + evt/offset + -20x-30
;avoid bounce around depending on how you approach item. evt/off is variable 0..x 0..y max
tip/offset: tip/extra/offset + 40x-10
;can skip all the above and use at tip/offset somehow?
]
;; on-over [ ;add event and tip-label where required
;; ;print ["Event over" event/offset event/away?]
;; show-tooltip event/away? event tip-label-x
;; ] tip-label-x: text yello "Squeek!" hidden
;complicated by compose paren preserved
;if required returning a block to another compose
;wasn't using compose and isn't finished yet
; cpd-button: func ["parametrize to view w/compose icon buttons copy paste delete"
; icon [string!] "name"
; padval [pair!] "moving tighten loosten pad amount"
; ;ttip "short description"
; tagref [string!] "prefix words for up/dn etc so no conflict"
; blk [block!] "action when clicked"
; ][
; icon: rejoin [cfg/icon-dir icon]
; ;if dropin to another compose, preserving paren a problem
; ; compose [ ;/deep
; ; pad (padval) ; -2x0
; ; base 20x20 (bg-color) draw (compose/deep [
; ; [scale 0.56 0.56
; ; ;preserve paren for target if compose
; ; ;image (to-paren append copy [load to-file] (icon))
; ; image (append copy [load to-file] (icon))
; ; crop 1x1 31x31
; ; ]
; ; ])(mold blk)
; ; on-over [either event/away? (compose [ ;since not /deep
; ; face/size: face/size - 2x2 face/color: (cfg/bg-color) + 12.23.56
; ; ]) (compose [
; ; face/size: face/size + 2x2 face/color: (cfg/bg-color) - 12.23.56
; ; ])
; ; show-tooltip event/away? event (tagref)
; ; ]
; ; ]
; ; ]
; compose/deep [ ;/deep?
; pad (padval) ; -2x0
; base 20x20 (cfg/bg-color) draw [
; [scale 0.56 0.56
; ; to preserve paren for target if using compose
; ; may not work the same with compose/deep
; ; image (to-paren append copy [load to-file] (icon))
; image load to-file (icon)
; crop 1x1 31x31
; ]
; ](mold blk)
; on-over [either event/away? [
; face/size: face/size - 2x2 face/color: (cfg/bg-color) + 12.23.56
; ][
; face/size: face/size + 2x2 face/color: (cfg/bg-color) - 12.23.56
; ]
; show-tooltip event/away? event (tagref)
; ]
; ]
; ]
; ]
;have to declare outside group-box. horribly hardwired position dependent resize breaks
; return across
; pad 370x-152
; tip2-copy: text center 60x20 ttip-color font ttfont "II copy ^^C" hidden
; probe cpd-button "3232.png" -2x0 "tip2-copy" [if x do y]
; halt
; Red [
; Title: {Adding transparency to images}
; Author: "Toomas V"
; Date: 2018-08-14
; File: %make-transparent.red
; ]
; make-transparent: function [img alpha][
; body: copy ""
; transp: copy ""
; repeat y img/size/y [repeat x img/size/x [
; append body copy/part enbase/base to-binary pick img as-pair x y 16 6
; append transp copy at enbase/base to-binary alpha 16 7
; ]]
; make image! reduce [img/size debase/base body 16 debase/base transp 16]
; ]
; [2018-08-14 12:33:11] <toomasv>
; Much better version of the above horrendously greedy one:
make-transparent: function [; <toomasv> Best so far
img alpha
][
tr: copy at enbase/base to-binary alpha 16 7
append/dup tr tr to-integer log-2 length? img
append tr copy/part tr 2 * 90000 - length? tr
make image! reduce [img/size img/rgb debase/base tr 16]
]
; <rebolek> How can I change image alpha?
; 8:49 AM
; >> i: make image! 1x1
; == make image! [1x1 #{FFFFFF}]
; >> i/alpha
; == #{00}
; >> i/alpha/1: 255
; == 255
; >> i/alpha
; == #{00}
;passing :anarea/text isn't getting appended
;set etext in on-create maybe
etext: none ;area or other text log to append string
msg-log: func [ "append info and error messages tlog and console, ^M newlines"
s [string!]
][
print [{msg log } s]
etext: rejoin [s newline copy/part etext 20000]
]
#define___tests__
;if find system/options/script "b64-png.red" [] ;
if any [no test+] [ ; no on
;#include %../libs/inclib.rd ;ohnoes, loads old commafy...
#include %../tests/testing.rd ;also replaces old commafy...
report-config/show 'all
report-form {cfg/init-pos} true -1x-1 < cfg/init-pos
report-form/strict/fail {/strict/fail 1.313} 1.3 1.313
report-form/fail {/fail 1.313} 1.3 1.313
;must be number
report-form {form-to-tv %} "21.500%" form-to-tv 21.5% 3
report-form {form-to-tv 1.010} "1.010" form-to-tv 1.01 3
report-form {form-to-tv 1.0100} "1.0100" form-to-tv 1.01 4
report-form {form-to-tv 1.1} "1.1" form-to-tv 1.05 1
report-form {form-to-tv} "1046.03" form-to-tv 1046.033 2
report-form {form-to-tv attempt trap non integer error} none
attempt [form-to-tv 1046.033 2.5]
;string or number
report-form {commafy-tv 1023.35} "1,023.35" commafy-tv "1023.35"
report-form {commafy-tv 1023.35} "1,023.35" commafy-tv 1023.35
report-form {commafy-tv 1023} "1,023" commafy-tv 1023
report-form {commafy-tv/precision 1023.35 3} "1,023.350" commafy-tv/precision 1023.35 3
;fixed error
report-form {commafy-tv/precision} "1,046.000" commafy-tv/precision 1046 3
;needs zero truncate option
;report-form {commafy-tv/precision} "1,046" commafy-tv/precision 1046 0
report-form {commafy-tv} "1,046.033" commafy-tv 1046.033
;string or number, rounds down?
report-form {calc-Kib ""} "" calc-Kib ""
report-form {calc-Kib none error} #[none] attempt [calc-Kib #[none]]
report-form {calc-Kib $} "0.242 Kib" calc-Kib "248"
report-form {calc-Kib 3} "0.242 Kib" calc-Kib 248 3 ;default?
report-form {calc-Kib 2} "0.24 Kib" calc-Kib/precision 248 2
report-form {calc-Kib 2} "0.33 Kib" calc-Kib/precision 340 2
report-form {calc-Kib 3} "2.000 Kib" calc-Kib/precision 2048 3
report-form {calc-Kib/Mib} "1.525 Mib" calc-Kib/Mib 1562048
report-form {calc-Kib/Gib} "0.002 Gib" calc-Kib/Gib 1562048
;report-form "join/with " "abc*xyz" join/with ["abc" "xyz"] "*"
; split-lines ; need new local name if tester includes its own?
t: split-lines { ^/^-o ne^/^-two^/^-three^/ ^-four^/}
report-form {split-lines } ["o ne" "two" "three" "four"] t
t: split-lines/keep-blanks { ^/^-o ne^/^-two^/^-three^/^-^/^-four^/}
report-form {split-lines/keep-blanks } ["" "o ne" "two" "three" "" "four" ""] t
t: split-lines/keep-indent { ^/^-o ne^/^-two^/^-three^/ ^-four^/}
report-form {split-lines/keep-indent } ["^-o ne" "^-two" "^-three" " ^-four"] t
t: split-lines/keep-blanks/keep-indent { ^/^-o ne^/^-two^/^-three^/ ^-^/ ^-four^/}
report-form {split-lines/keep-blanks/keep-indent } [" " "^-o ne" "^-two" "^-three" " ^-" " ^-four" ""] t
t: split-lines {__^/^-^-^-one__^/^-^-^-^-two^/^-^-^-^-^-three xyz^/}
report-form {split-lines __} {"^-one" "^-^-two" "^-^-^-three"} t
report-done
halt
]
if not any [
; fallback to embed or draw C/P
all [
icopy: attempt [load %./edit-copy.png]
ipaste: attempt [load %./edit-paste.png]
]
;work from gist copy or mydir
;exists? %../Images/tango/32x32/actions/edit-copy.png
;exists? %./edit-copy.png
; true ;buyer beware
; ok check less in dev mode
][
;silent exit compiled if missing, probably should b64 include
;print "can't find ./images" ;this won't work compiled either, need alert
;input or maybe ask can msg string, moot if no console
;alert "can't find some ../../images"
; alert "can't find some ./images"
; halt
;better
ifnt: make font! [name: "courier new" size: 23]
icopy: make image! reduce [40x40 snow]
draw icopy [pen black line-width 15 font ifnt text 3x2 "C"] ;font-size 12
;? icopy
ipaste: make image! reduce [40x40 snow]
draw ipaste [pen black line-width 15 font ifnt text 5x2 "P"]
;? ipaste
]
#define__gview___
gview: layout compose/deep [ ;[compose/deep ;can solve a few duplication's
title "base 64 png images"
size cfg/window-size
backdrop cfg/bg-color
style canvas: base 330x480 bg-color ; draw [] ""
;hardwired
; style rbutton: button 70x23 font [name: "Menlo" size: 9]
; can't seem to set font with map keys
; style rbutton: button 60x23 font cfg/fnt font-size 9
; style rbutton: button 60x23 font cfgfont font-size 9
;context words ok,
; might set cfg/sm med lg so can configure in one place
; still have way too many tweak numbers
style rbutton: button 70x23 font cfg/fnt font-size 9
style rtext: text 70x23 font cfg/fnt font-size 9 bold ;left
style rfield: field 110x25 font cfg/fnt font-size 10 bold
style rdlist: drop-list 110x25 font cfg/fnt font-size 10 bold
style rarea: area 300x125 font cfg/fnt font-size 10
tp: tab-panel [
" 1 " [
c: canvas
] " 2 test " [
rtext "rtext" [] rfield "rfield" rbutton "rbutton" []
return
rarea "rfield"
] " b64 " [
backdrop cfg/bd-color
;started this awhile ago never figured it out. never really settled ui required
; tighten it up
; browse & load img seems to work ok
; start from known b64 and create image
; resize panel & area not working great
; should log operations performed
; split tab out as a useful stand alone can put on gist
; update gui template to control color & fonts then drop in this tab
;need to test if setting image mangles sizes or will it round trip ok?
; first make image whatever natural size is then acale to view
; use raw-image otherwise
; memory not recovered so might leak loading many images
;; save/as 'ico might be useful
; some minimal validity checks done but could attempt [i: load too]
;add cls to areas maybe copy paste and copy to/from
; tempting to extract some common view item setup but not too bad yet
; could use react and /extra more
; make tab do image conversion to from base 64 that could work embeded rebol/red or html
;did I start this in dice?
;image to load/as 64# - Google Groups
;https://groups.google.com/forum/#!msg/red-lang/iJ9iBt36ses/sDRH9StNAwAJ
;write %image.txt rejoin [ "64#{" enbase read/binary %image.png"}"]
; bin: #{}
; save/as bin to-image view/no-wait [text "Hello World!"] 'gif
; str: enbase/base bin 64
;could do b64 on actual file contents or save as b64 pretty easily too,
; `list-dir`prints a string, rather than returning a block
; `normalize-dir` works, but it seems to be undocumented
; `read normalize-dir ...
pad 0x3 ;lossen
rtext 50 "from file"
;from chksum
;add 8.3/relative converter
;should be area resizable for multiple files? same with other fields and line numbered too
file-field: rfield 300 hint "file path" img-file-path
react [
face/size/x: face/parent/size/x - 250 ;
]
;on-create [file-field/text: ""]
;on-change [file-field/text: file-field/text] ;cvt to red path
pad 90x-8
sfgrp-cp: group-box 102x36 "" [ ;subject to resize
pad -4x-8
rbutton " . . . " 25x20 bold font-size 8 [
; /title => Window title. text [string!]
; /file => Default file name or directory. name [string! file!]
; /filter => Block of filters (filter-name filter). list [block!]
; /save => File save mode.
; /multi => Allows multiple file selection, returned as a block.
;../../tests/manual/image_size/ ;bunch of samples
ifile: request-file/file/title cfg/img-file-path "image to view"
;why not /dir like request-dir but I guess /file makes sense
; reopens at last dir even if reopen so red-lang remembers and /c/ just a hint?
;better if not force it must be image but may be best to load whatever
file-field/text: to-string ifile ;already red-path
;if extension is md5 or sha* parse list of files to hash relative or absolute
;will maybe error if not gif png jpg or at least not error
i: none
if all [
exists? to-file ifile
any [ ; not the final answer
find ifile ".jpg"
find ifile ".png"
find ifile ".gif"
]
][
i: attempt [load to-file ifile]
]
either image! = type? i [
img/image: i
;enable click from image button
wxh/text: form img/image/size
;ilen/text: calc-Kib (length? img/image/rgb)
ilen/text: calc-Kib (to-paren [length? img/image/rgb])
][
print sm: rejoin ["not valid image " ifile]
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
]
]
on-over [either event/away? [
;face/size: face/size - 2x2 face/color: bg-color - 12.23.56
][
;face/size: face/size + 2x2 face/color: bg-color + 12.23.56
]
show-tooltip event/away? event tip-browse
]
;won't work w/o compose, and didn't plan to use. woops
; unfinished parametrized version
; cpd-button "edit-copy.png" -2x0 "tip2-copy"
; [if ofile-txt/text [write-clipboard ofile-txt/text]]
; cpd-button "edit-paste.png" -2x0 "tip2-paste"
; [if ofile-txt/text [rc: read-clipboard if rc [ofile-txt/text: rc]
pad -2x0
base 20x20 bg-color draw [
[scale 0.56 0.56 image icopy
crop 1x1 31x31]
][if file-field/text [write-clipboard file-field/text]]
on-over [either event/away? [
face/size: face/size - 2x2 face/color: bg-color + 12.23.56
][
face/size: face/size + 2x2 face/color: bg-color - 12.23.56
]
show-tooltip event/away? event tip-copy
]
pad -2x0
base 20x20 bg-color draw [
[scale 0.56 0.56 image ipaste
crop 1x1 31x31]
][rc: read-clipboard if rc [file-field/text: rc]]
on-over [either event/away? [
face/size: face/size - 2x2 face/color: bg-color + 12.23.56
][
face/size: face/size + 2x2 face/color: bg-color - 12.23.56
]
show-tooltip event/away? event tip-paste
]
]
;have to declare outside group-box. horribly hardwired position dependent resize breaks
;keys not implemented, select all in rclick not duplicated
return
pad 440x-40
tip-browse: text center 70x20 ttip-color font ttfont "browse file" hidden
pad -50x0
tip-copy: text center 60x20 ttip-color font ttfont "copy ^^C" hidden
pad -50x0
tip-paste: text center 60x20 ttip-color font ttfont "paste ^^V" hidden
return
pad 5x5 ;loosen
;can I make this resizable? just a view window
img: image 200x200
on-create [
i: make image! [3x4 255.228.235.0]
img/image: i ;scales up or down accordingly I'll assume
;update wxh
wxh/text: form img/image/size
;ilen/text: calc-Kib (length? img/image/rgb)
ilen/text: calc-Kib (to-paren [length? img/image/rgb])
]
; on-change [
; ;doesn't trigger
; wxh/text: form img/image/size
; ]
below
;text 2x15 "" ;blank
pad 5x0
;may be simpler w/text-list or radio buttons. png, svg, red-lang
;requires more scriptable items to change display text & case actions
;default button text centered which looks weird in this group
;fix in style will change all.
; left makes no margin and ignores leading space? no gain just pain
; roughly 6x char width can just specify length no need length x height
rbutton 190 " make image from file-field" [
;trap error to display if any
i: none
if all [
exists? to-file file-field/text
any [ ; not the final answer
find file-field/text ".jpg"
find file-field/text ".png"
find file-field/text ".gif"
]
][
i: attempt [load to-file file-field/text]
]
either image! = type? i [
img/image: i
wxh/text: form img/image/size
;ilen/text: calc-Kib (length? img/image/rgb)
ilen/text: calc-Kib (to-paren [length? img/image/rgb])
][
print sm: rejoin ["not valid image " file-field/text]
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
]
]
pad 0x6 ;loosen
; text 2x0 "" ;blank
; pad 0x-3 ;tighten
rbutton 190 " make image from-b64" [ ;offer to save, try to load
;forget where clipped from
;image: load/as debase your-image.base64 'png
;b: load/as #{...} 'png`
s: split from-b64a/text #","
;chk split properly, was well formed msg otherwise
either all [ ; minimal valid
2 = length? s
s/1 <> "data:image/png;base64,"
;attempt [img/image: load/as debase s/2 'png]
debase s/2
][
][
print sm: "invalid operation with from-b64a text"
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
return 'done
]
;i: make image! debase probe trim last s ;nope
;i: debase trim/with last s " ^-^/" ;nope
;i: make image! debase trim/with last s " ^-^/" ;nope
; *** Script Error: cannot MAKE/TO image!
; from: #{89504E470D0A1A0A0000000D494844520000001A
;starting from square one every time
; what else could it be?
; >> to-hex #{89504E470D0A1A}
; *** Script Error: to-hex does not allow binary! for its value argument
; >> to-string #{89504E470D0A}
; *** Access Error: invalid UTF-8 encoding: #{89504E47}
; >> form #{89504E470D0A}
; == "#{89504E470D0A}"
; >> mold #{89504E470D0A}
; == "#{89504E470D0A}"
; [2018-04-26 10:38:38] <rebolek> image: load/as debase your-image.base64 'png
; [2018-04-26 10:39:11] <maximvl> thanks!
i: attempt [load/as debase trim/with last s " ^-^/" 'png]
either image! = type? i [
img/image: i
wxh/text: form img/image/size ;could react or on-change
;ilen/text: calc-Kib (length? img/image/rgb)
ilen/text: calc-Kib (to-paren [length? img/image/rgb])
][
;doesn't work 2nd time at all?
print sm: "invalid operation with from-b64a text"
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
]
]
pad 0x-3 ;tighten
rbutton 190 " make to-b64 from image " [
to-b64a/text: rejoin [{data:image/png;base64,}
;something something who knows what
;form enbase img/image/data ;none
;form enbase img/data ;nope
;form enbase img/image ;nope
;form enbase img
;*** Script Error: enbase does not allow image! for its value argument
; [2019-02-07 10:40:58] <endo64> print {<img src="data:image/png;base64,}
; print enbase to binary! load %file.png
; also said try i/rgb
; form enbase to-binary img/image/rgb ;looks wrong
; form enbase to-binary img/image/rgba ;nope
;form enbase img/image/rgb ;still looks wrong
;form enbase load img/image ;nope
;form enbase load img/image/rgb ;nope
;form to-string enbase img/image/rgb ;still wrong
;enbase img/image/rgb ;still wrong
; enbase img/image/rgb ;nope, looks wrong
; help img list object items
; help img/image views image so how to get list?
; source img/image just shows values in console
; how to discover img/image/rgb
;enbase source img/image/rgb ;nope
enbase probe img/image/rgb ;nope
]
;isn't triggering to-b64 on-change
ilen/text: calc-Kib (to-paren [length? img/image/rgb])
print sm: "from- image to-b64a text"
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
]
pad 0x-3 ;tighten
rbutton 190 "make to-b64 from file-field" [ ;can work directly w/png?
i: none
if all [
exists? to-file file-field/text
any [ ; not the final answer
find file-field/text ".jpg"
find file-field/text ".png"
find file-field/text ".gif"
]
][
i: attempt [load to-file file-field/text]
]
either image! = type? i [
img/image: i
wxh/text: form img/image/size
;ilen/text: calc-Kib (length? img/image/rgb)
ilen/text: calc-Kib (to-paren [length? img/image/rgb])
to-b64a/text: rejoin [{data:image/png;base64,}
;something something who knows what
; [2019-02-07 10:41:16] <endo64>
; print {<img src="data:image/png;base64,}
; print enbase to binary! load %file.png
; print {"}
; Didn't test, but it should work
; (not sure about `to binary!` is necessary or not)
; Or may be:
; i: load %file.png
; print enbase i/rgb
enbase to-binary i ;looks no better direct from png
; enbase to-binary i/rgb ;looks no better direct from png
; may only work w/png?
enbase to-binary i ;looks no better
]
][
print sm: rejoin ["not valid image " file-field/text]
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
]
]
; ========================== 2nd row of buttons after this last one ====
across ; jump to get to top of image again, don't want to alternate
pad 0x-3 ;tighten
rbutton 190 "write-clip to-b64 as html" [
; put b64 and div img markup into copy buffer
s: rejoin [
{<Br />
<div class="">
<img src="} to-b64a/text
{"
onclick="" class="" hspace="2">
<!-- size }
form img/image/size
{ -->
</div>
}]
write-clipboard s
]
pad 0x-120 ;jump
below
rbutton 190 " optimize image RSN" [print "nope"]
pad 0x-3 ;tighten
rbutton 190 "make image transparent " [
img/image: make-transparent img/image
print sm: rejoin [" image made transparent, UN-TESTED"]
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
]
pad 0x12 ;loosten
rbutton 190 " make image from to-red " [
i: reduce attempt [probe load probe trim/with/all copy to-b64a/text "^- ^/"]
; imgdata has no value till reduce
;attempt [ ;masks error need to catch otherwise
print ['i mold i newline 'imgdata mold imgdata]
;]
i: ;attempt [
;make image! reduce debase imgdata
make image! probe debase imgdata
; ]
either image! = type? i [
img/image: i
print sm: rejoin [{made image from to-b64 as red-lang}]
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
][
print sm: rejoin [{wasn't image in to-b64 for red-lang}]
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
]
]
pad 0x-3 ;tighten
rbutton 190 " make to-red from image " [
;s: trim/with/all copy mold/all img/image/rgb newline
;s: trim/with/all copy mold/all img/image "^-^/"
s: trim/with/all mold img/image "^-^/"
probe copy/part s 256
to-b64a/text: rejoin ["imgdata: {"
; sourcec img/image shows values, b64 them but for use in script
enbase s "}"
]
;isn't triggering to-b64 on-change to show len chars
t64len/data: length? to-b64a/text
print sm: rejoin [{made to- red-lang img word image
to use img: make image! reduce debase string!} newline s]
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
]
text 2x15 "" ;blank
across ;still below, drop areas below img
return ; goes to next left
; may want to resize resample
; [2018-08-15 23:54:56]
; <toomasv>
; view [
; s: slider with [extra: is [255 * data]]
; [t1/text: form s/extra]
; t1: text
; ]
; [2018-08-16 06:05:03] <rebolek> >> string: "abac"
; [2018-08-16 06:05:03] <rebolek> == "abac"
; [2018-08-16 06:05:03] <rebolek> >> f: make path! [replace all]
; [2018-08-16 06:05:03] <rebolek> == replace/all
; [2018-08-16 06:05:03] <rebolek> >> do reduce [f string "a" "x"]
; [2018-08-16 06:05:03] <rebolek> == "xbxc"
; 2018-08-16 06:53:31] <toomasv>
; view [
; s: slider extra object [value: 0]
; react [face/extra/value: 255 * face/data]
; [t1/text: form s/extra/value]
; t1: text
; ]
;make react to img/image change
pad 0x-8 ;tighten
rtext 90 "width x height" wxh: rtext 70 "wxh" pad 10x0
rtext 40 "length" ilen: rtext 100 ""
return
pad 0x-8 ;tighten
rbutton 80 "save image" [
;trap error to display if any
;wrap in quotes maybe
; confirm write to dir, default script dir
;write/binary/as to-file ofile/text img/image 'png reserved?
;may need confirm replace if exists means showing file details
;default is overwrite
; img/image is just molded not a valid image
; to-binary img/image either
;write/binary to-file ofile/text to-binary img/image 'png
;write/as to-file ofile/text img/image 'png ;reserved?
; chk overwrite
save/as to-file ofile-txt/text img/image 'png
; confirm wrote to dir
;fp: to-string pwd ;is just an output action?
;print ["wrote " ofile/text " to " pwd] ;pwd outputs before print
fp: to-string get-current-dir
print sm: rejoin ["wrote " fp tab ofile-txt/text newline clean-path %./]
b64status/text: rejoin [sm newline copy/part b64status/text 25000]
;isn't modifying b64status, could set with return val
; msg-log :b64status/text rejoin ["wrote " fp tab ofile/text newline clean-path %./]
]
ofile-txt: rfield 380 "some.png" ;default dir script dir unless use ifile
react [
face/size/x: face/parent/size/x - 250 ;
]
pad 10x-8
sfgrp-cp2: group-box 102x36 "" [ ;subject to resize
pad -4x-8
rbutton " . . . " 25x20 bold font-size 8 [
ofile: request-file/save/file/title ofile-txt/text "directory to save image"
ofile-txt/text: to-string ofile ;already red-path
]
on-over [either event/away? [
;face/size: face/size - 2x2 face/color: bg-color + 12.23.56
][
;face/size: face/size + 2x2 face/color: bg-color - 12.23.56
]
show-tooltip event/away? event tip2-browse
]
;won't work w/o compose, and didn't plan to use. woops
; unfinished parametrized version
; cpd-button "edit-copy.png" -2x0 "tip2-copy"
; [if ofile-txt/text [write-clipboard ofile-txt/text]]
; cpd-button "edit-paste.png" -2x0 "tip2-paste"
; [if ofile-txt/text [rc: read-clipboard if rc [ofile-txt/text: rc]
pad -2x0
base 20x20 bg-color draw [
[scale 0.56 0.56 image icopy
crop 1x1 31x31]
][if ofile-txt/text [write-clipboard ofile-txt/text]]
on-over [either event/away? [
face/size: face/size - 2x2 face/color: bg-color + 12.23.56
][
face/size: face/size + 2x2 face/color: bg-color - 12.23.56
]
show-tooltip event/away? event tip2-copy
]
pad -2x0
base 20x20 bg-color draw [
[scale 0.56 0.56 image ipaste
crop 1x1 31x31]
][rc: read-clipboard if rc [ofile-txt/text: rc]]
on-over [either event/away? [
face/size: face/size - 2x2 face/color: bg-color + 12.23.56
][
face/size: face/size + 2x2 face/color: bg-color - 12.23.56
]
show-tooltip event/away? event tip2-paste
]
]
;have to declare outside group-box. horribly hardwired position dependent resize breaks
return
pad 450x-70
tip2-browse: text center 70x20 ttip-color font ttfont "browse file" hidden
pad -50x0
tip2-copy: text center 60x20 ttip-color font ttfont "copy ^^C" hidden
pad -50x0
tip2-paste: text center 60x20 ttip-color font ttfont "paste ^^V" hidden
return ;why need 2nd return? hidden messes layout
pad 0x47
rtext 60 "from b64:" ;need length on b64, beyond a few lines not great in html
pad 0x-3 ;tighten
from-b64a: rarea 455x75
; from irccloud, pack descript text, make selectable examples
{data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAADsklEQVR4AZWUTWic1RfGfyd58zFNVQg12jQttNgq3QQqLtwYF25EdBGpqIgVRAQ/IAoJ/03/iy6D0OJCRCooCtkquGlBMAsFoV24EMWvgk1jIzRpsHY6M+89x7xzz51557UZ4oXhue+dy/l47nMeAZhdsCkbZhFhRmCS/gsz9Z1gFjBAQw4CqgFBCJqvCizfvJUvACtSJGGE74DxnSbQAs2KoDF4iGiqAEUSL6PYh/VW3pjOik6kTxIzA2JQESGEvMD2t5l1CrCY2L8DGIQCYVxMFrOCrm0r1wItddAJohqRSBECqAdPmLq19lk+I7MnzbrBpVq9U9XhvY26hQZY6iDtBUIIiHgiupiZaaKiTEMvevIS74j0dmGWuiQW6AWJCGaQqWlbMYJ3IKVgjhN35cwdr3Fo3yhjo8JfN5VLq3XeWdrk6gblykticVRrozz5v7rdTj2Gtel47FjgzWf2MJxJRxxpNVvG6aUrnLuQOvagqSvxrhDk8flNk4pkzSnaO97i/fkJhoeknUAkoqp29s3cePHUJdY2XImxmiSojlgyLVEEZZ4Dr8/uZiiLXZR/5c6KTuef38Nb764l0RQY73piM42JrCzNEt+H99d6qEr76vfBvaOE0ASE3DsgCczpy4oLias0jEf2tXj72Ql212TbBOWzO8cG0ZJKtcDOu8dzefSN363cxQNTgdNzB9K7VKvftkNV4/qNFh9/cZmlLzd6ZhJAHnntN0tyRODswt1bMq5VO0iYRFFN7LMYqz+z9MtWsutlS/I3Sl5lgamJke266HfujhCpPvHEAT49/2e842xleWgB1pkdtf40+b4v3jGWEbQjsCjv5FfJxy6v1blvapcbanntvIDNGy2KuMmiLM1RGqpgyv8/+JWPTh4lG+wZ0mrAvkV8+PnP7ZiJpQLl2IkLZhVXOHQvnHr1MPvvqTEyNLCjWQpB2fy7xdnPfuKTc1fdzlzNZsj0C9+4vLVHjknyu0YHWH7vIQAaTeXhV752wy25dsUrMesZVpBI3e1cwTzIg0e6Krz4wzXyvBnvOSWl942Jtetz6X+wf8tbklTdKV5+6ii3GoGLP15j7sz3Tm83mLpLB688nVeX3H/8/BVgMiVASGbo6JULvbzjFHng7RL4tdVM87CM8FyUYtXenWORRIljqFbfd4mwPFg7OPutDOhLYDV/RDfIKM2gwUWSO8Vd3ne0zNYbzcbTWb2+vgLj01lmi6phRmRgMklSLSnR+K/L4A+Br7aSLAAr/wDaS9qC26tiWQAAAABJRU5ErkJggg==
}
; from bing
; {svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMTYgMTYiPjxwYXRoIHN0cm9rZT0iIzc2NzY3NiIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZD0iTTEgMWwxNCAxNE0xNSAxbC0xNCAxNCIvPjxwYXRoIGZpbGw9Im5vbmUiIGQ9Ik0wIDBoMTZ2MTZoLTE2eiIvPjwvc3ZnPg==
; }
react [
;only seems to react once at create inside panel
;wrap prevents scroll?
face/size/x: vp/size/x - 90 ;
]
on-change [ ; doesn't trigger from create or at all if programatically?
;f64len/text: 12 ;form length? face/text
f64len/data: form length? face/text ;why not /text?
]
on-create [ ;length? none error
f64len/data: length? face/text
]
return
pad 0x-35 f64len: rtext 30 "-+-" pad -30x35
rbutton 90 "swap to from" [
s: copy from-b64a/text
from-b64a/text: copy to-b64a/text
to-b64a/text: s
;on-change not triggering programatically?
f64len/data: length? from-b64a/text
t64len/data: length? to-b64a/text
]
rbutton 60 "clr from-" [
clear from-b64a/text ""
]
rbutton 60 "clr to-" [
clear to-b64a/text ""
]
across
return
pad 10x00
;wraps or cuts off if text too long, ~x4*chars
; from-b64f: rfield 350 "b64 sample irccloud. description from-b64"
;needs copy to to from button and chg description field too on-change
; return
rtext 60 "to b64:"
pad 0x3 ;
to-b64a: rarea 455x75 "data:image/png;base64,..."
react [
face/size/x: vp/size/x - 90 ;
]
on-change [
t64len/data: length? face/text
]
on-create [
t64len/data: length? face/text
]
return
pad 0x-35 t64len: rtext 30 "+-+" pad -30x35
;embed form of image
; Date Added: 01-20-2020(04:11pm)
; Convert Images to REBOL Script
; foreach f load %./ [if find [%.png %.jpg %.bmp] suffix? f [write/append %images.r reform [mold f mold read/binary f newline]]]
; Summary: This line converts all your PNG, JPG, and BMP image files into a REBOL formatted file for including them in a script. (For base64 encoding, set system/options/binary-base: 64)
; Author(s): Anonymous
; need mode buttons to change buttons & prompts to also do rebol/red embed
b64status: rarea 465x60 "the latest news"
on-create [
;fuk, didn't work
;etext: :face/text ;area or other text log to append string
;face/text also didn't work. face/data none on area
etext: face/text ;area or other text log to append string
;msg-log rejoin ["for process errors " tab " current dir " clean-path %./]
append face/text rejoin [" of process errors "
newline " current dir " clean-path %./
]
]
below
;chg to use compose
rbutton 95 "? ^M^/ cheatsheet" [ ;no button multiline?
; may need wider on higher DPI screen
ws: 430x440 ;overall popup window size
wst: ws - 20x70 ;text area
;wok: as-pair to-integer (wst/x / 2) - 30 10 ;center ok
wok: as-pair to-integer (to-paren [(wst/x / 2)]) - 30 10 ;center ok
view layout [
title "b64 png HELP!"
size (first [ws])
backdrop beige
;rtext "HELP!" ;style not inherited
text (first [wst]) #FFFFFF no-border font [
name: "Consolas" size: 11
color: hex-to-rgb #000000
] {HELP!}
on-create [
;remove leading indent. need ___ guide to limit strip, RSN
; ^M needed for newline in text? in window?
; single & accelerators getting eaten in windows
s: split-lines/toinsert {_____________________
B64 'png HELP!
a little utility to work with base 64 image data
most often used in html for small images && icons.
buttons should be self explanatory?
images are shown with size and length.
created from a path, by browsing
with the `...` browse or from base 64
data in the lower from-b64 area.
You can save the image to file.
later optomize and maybe resize images
paste b64 png data into from-b64 area to use
or test. the buttons get data from
and put results to different places.
You can create base 64 image data,
then copy to clipboard in html form.
does some minimal checking for valid image.
} "^M^ "
;probe s
;skip 1st line. count any underscores 1st line
; remove only that many spaces or 4x/tab indentations
;will be different if tabs are spaces, no guarentee
;moved to split-lines
; u: take s u: probe to-integer (to-paren [(length? u)]) / 3.2
; foreach x s [trim/tail x take/part x u insert x "^M "] ;win
;probe s
face/data: rejoin [s] ;newline length? u
]
return
pad (first [wok]) button "ok" [unview]
]
]
rbutton 50 "clr log" [
clear b64status/text ""
]
]] ;e panel
react [
;this react should also move exit buttons too but doesn't trigger
;could be order needs to be rearranged but above my paygrade
; may need to go back to more tedious event-function resizing, locks buttons
face/size/x: face/parent/size/x - 15 ;
;center it for no particular reason
face/offset/x: to-integer face/parent/size/x - face/size/x / 2 ;
face/size/y: face/parent/size/y - 45 ;
]
return
; rb: rbutton 27 "xyx" []
; rfield "The quick brown fox jumped straight over the lazy dog"
pad 360x-15
rbutton "Exit View" [unview] ;just exits view interpreted
rbutton "Quit All" [quit] ;same as unview & halt compiled
]
;"geany sidebar bookmark
#define_end_gview___
print tp/selected: 3 ;starts with b64 tab
; insert-event-func [
;there is no create to start with. have to put on-create at the item
;rclick is a simple up/dn, action in console also catches
;
;if event/type <> 'time [print ["events: " event/type]]
; if all [event/window = viewer event/type = 'resize] [
; print ["size-pos " event/window/size tp/offset tp/offset]
; ; tp/size/x: event/window/size/x - 20 - tp/offset/x
; ; tp/size/y: event/window/size/y - 60 - tp/offset/y
; ;no diff cmt
; ;'done
; ]
; ]
; locked up all buttons. need to kill from task manager
; even with everything commented inside
; wtf, using this fine in other scripts
;/no-wait problematic w/o halt or print to console recently
view/no-wait/flags/options gview ['resize][offset: cfg/init-pos]
;if need to use compiled -e or maybe console, leave out /no-wait
;; view/flags/options gview ['resize][offset: cfg/init-pos]
; can save screen windows as image
; img-out: to-image img-panel
; save/as %panel.png img-out 'png
comment {
todo
add
image/svg+xml base64 decode/encode
other claasic rebol/red embedded image format from url
selector + copy & paste at b64 area for more example code
color scheme font theme pick ligh/dark/solorized ligh/dark user
fix
image/png base64 encode, not sure how
make image from red-b64 not working yet, seems like it should work now.
not sure hasty length display on image accurate or reliable on-change
think transparent needs to set a palette color transparent?
tootips need timeout, browse sticks when click button, starts selected
known image memory leaks if use continuous make new image!
maybe
parse multiple from file and add url
image resize
optomize image, reduce size in various ways
redCV can do things in compiled version
, can they fallback interpred slower code?
commandline processing from sendto shortcut
call converter to/from display other image formats, tif gif89a
batch mode
saveas more than 'png
decode formats gif89a animations, ico
make qrcode from- maybe read qrcode to/from image
make image zoom so can read w/old phone qr reader
do urlencode/decode enhex/dehex from-/to-
ocr on image might be good, convert tiff/grey scale might be required
refactor
add format selector, then swap text to change buttons
rather than new sets of buttons for each format
more tests
parametrize tooltips
using chevron CSS Bookmarklets Adrian Roselli\style.css
github gradient
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12MwuCXy3+CWyH8GBgYGJgYkAABZbAQ9ELXurwAAAABJRU5ErkJggg==
shorter example, shorter base64 png: problem, how to enbase?
Red []
view layout compose [
title {problem: how to enbase?}
atxt: area 350x100
{data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAACWBAMAAADOL2zRAAAAD1BMVEUAAAAAAAAAAAAAAAAAAABPDueNAAAABXRSTlMAQCAvERmeAPMAAABZSURBVGje7dCxDYAwEARBRAcPDUAp9N8U8QcvAmRZtmfCi1a3AQAAE7sjOcr92x7ZVe2yZMmSJUuWLFmyumc9kZzl3qbr/1/ChAkTJkyYMGHCFgsDAAAG9QIQUZ5P5aEjUwAAAABJRU5ErkJggg=="
}
btxt: area 350x100 ""
return
i: image 30x30
on-create [(
face/image:
attempt [load/as debase last split trim/with atxt/text " ^-^/" #"," 'png
]
)]
across
pad 20x10
;button "clear image" [draw i/image [pen black line-width 15 text 3x2 "C"]]
;button "clear image" [ i/draw: [pen black line-width 15 text 3x2 "C"]]
;button "clear image" [ i/image: make image! [80x80 green]] invalid arg green
button "clear image" [i/image: make image! [80x80 200.255.200.0]]
button "make image from A area" [
i/image: attempt [load/as debase last split trim/with atxt/text " ^-^/" #"," 'png
]
]
button "make b64 from image to B area" [
either image! = type? i/image [
btxt/text: rejoin ["data:image/png;base64,"
; enbase probe i/image/rgb ;doesn't look right
; enbase to-binary i/image/rgb ;doesn't look right
;
; enbase mold i/image/3 ; /2 /3 nope
;enbase form i/image/3 ; /2 /3 nope to-binary form , all 0's?
;enbase to-binary debase/base mold i/image 16 ;
;enbase form i/image/rgb ;
;enbase debase/base form to-binary i/image/rgb 16 ;error is none
;enbase debase/base mold to-binary i/image/rgb 16 ;error is none
;enbase to-binary i/image/rgb ;
enbase to-binary :i/image/rgb ;
;enbase to-binary enbase/base to-binary i/image/rgb 16
;enbase to-binary debase/base mold i/image/rgb 16 ;error is none
]
][btxt/text: "bad image"]
]
return
button "swap areas" [s: copy atxt/text atxt/text: copy btxt/text btxt/text: s]
pad 60x0
button "exit" [unview]
]
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAEklEQVQImWNg0Db1ZVCxc/sPAAd4AlUHlLenAAAAAElFTkSuQmCC
some don't end w/==, js debase must be more forgiving.
that one worked, not all do
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACsAAAAWBAMAAACrl3iAAAAABlBMVEUAAAD+AciWmZzWAAAAAnRSTlMAApidrBQAAAB5SURBVBjTbZABDoAwDALZD/j/a02L0M7Y6WbTkzCA/zoq1JoOYE9rJ5nuwGzTb1cTUSRWF9r/hLZ2bdFeTs5ykqLUxzdCItqWbDc5NBatR9IcUX00bWAcXD7gPHTdOPUbal/QISaFiH8SvFK58l5xWJvcOSbBJFn1AL8UBOS20mNLAAAAAElFTkSuQmCC
\libs\bitbegin\qrcode-master\qrcode.red
~1700 lines is not small
*RSN real soon now *TBD to be done whenever
}
@ne1uno
Copy link
Author

ne1uno commented Sep 23, 2022

enbase save/as none i/image 'png ;works.
see red/sandbox on gitter, will update gist when my internet is less flaky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment