You are not logged in.

#1 2022-03-18 07:08:06

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,959
Website

The Smileotron

OK you make a new directory somewhere and any time you run across a smiley on the web that you might want to use in a forum post some day you just drop it in there. Keep to small images so the imgur GUI won't kick in and load a whole web page when you try to use it.

Now put the script below in your ~/bin (make sure /<username>/bin is in your $PATH), make the script executable and bind it to some key combination in ~/.xbindkeysrc (I use Win+S).

When you want to use one of those cool smileys you've collected, hit your key combo and click the smiley in the feh window that pops up. If it's the first time you've used that smiley you'll need to wait a second or two for the file to be uploaded and the window to close, but then you can do a middle-click to paste it into your forum post. (Esc to cancel)

If you've already used that smiley the url will be recorded in a <filename>.url file so the upload won't have to be repeated.

Dependencies: feh curl xsel jq

Edit the top two lines to taste.

#!/bin/bash
## The Smileotron:
## choose an image file from a folder, upload if necessary
## and get its url + bbcode to paste.
## Dependencies: feh curl xsel jq

# anonymous ID for imgur service
ImgurID=ea6c0ef2987808e

# set your folder for smileys (and put some there)
SMILEY_DIR="$HOME/Pictures/smilies"

###################################################

missing=()
for i in feh curl xsel jq
do
    hash "$i" 2>/dev/null || missing+=(" $i")
done
[[ ${missing[0]} ]] && {
    echo "$0: This script requires the following commands: ${missing[*]}
Please install those packages and rerun the script." >&2
    exit 1
}

[[ -d $SMILEY_DIR ]] || {
    echo "$0: $SMILEY_DIR no such directory" >&2
    exit 1
}

[[ $1 = --load ]] || {
    exec feh -t "$SMILEY_DIR" --quiet --title 'Click a smiley' --index-info '' --image-bg black --action "$0 --load %F;"
    exit # only used if feh call fails
}

####################################################

# if "--load" option passed, upload image (if necessary) and print out url

file="$2"
ext=${file##*.}

feh -U "$file" >/dev/null 2>&1 || { echo "$0: $2 no such image file in $SMILEY_DIR" >&2; exit 1;}
[[ -f ${file}.url ]] || {
    img_id=$( curl -sH "Authorization: Client-ID ${ImgurID}" -F image=@"$file" https://api.imgur.com/3/image | jq --raw-output '.data.id' )
    echo "https://i.imgur.com/${img_id}.${ext}" > "${file}.url"
}

# uncomment end of next line to use clipboard instead of selection
printf '[img]%s[/img]' "$(<"${file}.url")" | xsel --input #--clipboard
pkill -f "feh -t $SMILEY_DIR" # unnecessary?
exit

mL2R4Kt.png

Last edited by johnraff (2022-03-19 05:09:07)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#2 2022-03-18 14:26:33

sleekmason
zoom
Registered: 2018-05-22
Posts: 871
Website

Re: The Smileotron

A new shiny toy!  big_smile

Absolutely love the stuff you come up with. Looking forward to checking this out.

Offline

#3 2022-03-18 18:14:30

sleekmason
zoom
Registered: 2018-05-22
Posts: 871
Website

Re: The Smileotron

I tested this by grabbing some of the icons in /usr/share/icons
The black ones are adwaita 24x24 and the others are gnome 32x32

s35XUXZ.png1CKamDE.png8C3PCEb.pngN5issC7.pngBkXLY8E.pngmWuSKv5.pnggCIMzjc.png

This is pretty cool:)

smile  big_smile  cool   wJYTIBg.pngroKrWNk.pngRgAicS8.png It looks like the 22x22 match the built in set.

Grabs the window border as well, but so what?  I kinda dig it. BkXLY8E.png

pkill -f "feh -t $SMILEY_DIR" # unnecessary?

I think it would be better to leave commented so as to allow multiple single selections. (multiple single selections, I know, I know).

At first, I was going to ask why not make it multiple choices all in one go, but I can see the reasoning not to as well.  In any event, I would at least keep the selection box open until closed by the user. 8C3PCEb.png

Okay, this is fun.


To recap, er . .  at least what I did:

Grab the script and place it in ~/bin. name it 'smilies', and make it executable.
You may need to make the ~/bin folder if doesn't exist. Logout/in (<-- this may be a reboot),if you had to add the folder for ~/bin to be in your $path.

You may want to comment line #40 of the script if you want the window to stay open. (you probably will at first anyway:)

Use the xbindkeys utility, or edit the file ~./xbindkeysrc and add something like:

#Smiles
"smilies"
   Mod4 + s

This assumes your 's' key isn't already being used. Adjust as necessary.

Make a new folder in home: ~/Images/smilies to put your new smilies in.  You can change this as desired on line 11 of the script.( Also note the capital "I" in Images if left as is). Open another thunar instance and go to /usr/share/icons/gnome/22x22/emotes for some new smilies to use, or grab from anywhere you want, though you may need to adjust the sizes. (Gimp is your friend).  You don't need to be root to copy from /usr/share/icons.

That's it for preparation.

Now, when responding in a post online, just hit 'super + s' (super is the windows key).
This brings up the cool feh box with all of your smilies.
click on one, but only one at a time.
right-click in your browser window to 'paste' the icon where ever you want in your post. XRaEXsx.png You can also middle click if you prefer.

Click on another smiley while the window is still open and repeat as desired.

Don't forget you will need feh, and if you grab any of the black icons from the adwaita folder, you won't be able to see them. You may need the clipboard active for right-click -> paste to work.  Middle click worked here regardless.

Really nice N5issC7.png

Last edited by sleekmason (2022-03-18 21:24:12)

Offline

#4 2022-03-19 04:54:02

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,959
Website

Re: The Smileotron

Glad you enjoyed it! smile

This was a script I wrote back in the CrunchBang era, but I still use it often, without apparent problems.

sleekmason wrote:

Grabs the window border as well...

Sorry, don't quite get this. What exactly is happening?

pkill -f "feh -t $SMILEY_DIR" # unnecessary?

I think it would be better to leave commented so as to allow multiple single selections. (multiple single selections, I know, I know).

I guess allowing multiple selections might be an enhancement. Personally, I never want to add more than one smiley at a time though, so it wouldn't be high on my priority list. If commenting out that line does the job for others, then fine.

At first, I was going to ask why not make it multiple choices all in one go, but I can see the reasoning not to as well.  In any event, I would at least keep the selection box open until closed by the user.

It's one less keypress. Also, the window closing itself is a signal that the smiley is ready to paste.

Also note the capital "I" in Images

Good point! That capital I came in from my personal setup. In fact Pictures would be more generic. Maybe I'll change the OP script.

Don't forget you will need feh

Thanks for the reminder. As I said, it's an old script with no fancy trimmings like a --help option, but at least I should add a test for the necessary commands feh curl xsel jq

EDIT: added a check for those four commands and changed Images to Pictures in the default directory path.

Last edited by johnraff (2022-03-19 05:10:49)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#5 2022-03-19 12:55:13

sleekmason
zoom
Registered: 2018-05-22
Posts: 871
Website

Re: The Smileotron

johnraff wrote:
sleekmason wrote:

Grabs the window border as well...

Sorry, don't quite get this. What exactly is happening?

Just the difference between  cool  with just the smiley, and  wJYTIBg.png  which has the border frame around the smiley as well.

Last edited by sleekmason (2022-03-19 14:21:38)

Offline

#6 2022-03-20 02:59:53

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,959
Website

Re: The Smileotron

sleekmason wrote:
johnraff wrote:
sleekmason wrote:

Grabs the window border as well...

Sorry, don't quite get this. What exactly is happening?

Just the difference between  cool  with just the smiley, and  https://i.imgur.com/wJYTIBg.png  which has the border frame around the smiley as well.

The only difference I can see is that the cool smiley image is made with the image bounday tight around the face, while wJYTIBg.png has a wider background. Maybe you could edit the latter image in gimp to crop off the unwanted extra background.

But this is nothing to do with the script itself, but what images you choose to put in your smileys directory.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#7 2022-03-20 12:52:56

sleekmason
zoom
Registered: 2018-05-22
Posts: 871
Website

Re: The Smileotron

Screenshot-from-2022-03-20-07-44-11.png

Here is what I see in both Lilidog with Firefox and on my phone using Opera. Different colors and night/day settings make no difference.

Maybe BL has a package installed that helps with this unbeknownst when making the script?

Offline

#8 2022-03-20 16:28:45

sleekmason
zoom
Registered: 2018-05-22
Posts: 871
Website

Re: The Smileotron

@misco_2083 Neat! ♨️ After opening  ctrl +: and selecting, I had to copy and paste the results from the window.  Is it supposed to copy on "Ok"?  Anyway, these are all really cool.  Thank you for posting:)   ⚓️

Last edited by sleekmason (2022-03-20 16:30:20)

Offline

#9 2022-03-20 18:54:05

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 1,762

Re: The Smileotron

^I tested with convert here because shrinking smileys using gimp is a curly for me.
All smileys have a size of ~3 - 7kB. I wanted them to be 50% smaller.

The directory small_pics is created, but convert refuses to reduce the size. Surely one of you can see where the error is.

$ test -d small_pics || mkdir small_pics && for i in *.png; do convert -resize 50% "$i; " "small_pics/$i"; done
convert-im6.q16: unable to open image `amazing-sm.png; ': Datei oder Verzeichnis nicht gefunden @ error/blob.c/OpenBlob/2924.
convert-im6.q16: no decode delegate for this image format `PNG; ' @ error/constitute.c/ReadImage/575.
convert-im6.q16: no images defined `small_pics/amazing-sm.png' @ error/convert.c/ConvertImageCommand/3229.
convert-im6.q16: unable to open image `bad-egg-sm.png; ': Datei oder Verzeichnis nicht gefunden @ error/blob.c/OpenBlob/2924.
convert-im6.q16: no decode delegate for this image format `PNG; ' @ error/constitute.c/ReadImage/575.
...

XbW1mwr.png


However with this it does:

$ for i in *.png; do convert $i -resize 50% $(basename $i .png).png ; done

L20hk6N.png  Jq9QN6O.png

Offline

#10 2022-03-21 04:41:19

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,959
Website

Re: The Smileotron

sleekmason wrote:

https://i.postimg.cc/Js9Yc4pB/Screenshot-from-2022-03-20-07-44-11.png

Here is what I see in both Lilidog with Firefox and on my phone using Opera. Different colors and night/day settings make no difference.

Maybe BL has a package installed that helps with this unbeknownst when making the script?

It's not the script. The images you post, using the script on Lilidog, look identical to the ones I post running the script on BL.
On Firefox 91.6.1 on BL, I see no border round the uploaded images, either yours or mine, even using a different forum theme.

However, on my android phone, using Firefox I don't see the images at all, only links, and using Google Chrome  I do see the borders round the smileys, both yours and mine. yikes

Finally I checked out the html source code being served out by the forum for a forum smiley and an uploaded image:

The only difference I can see is that the <img src="https://forums.bunsenlabs.org/plugins/ezbbc/style/smilies/cool.png" alt="cool"> smiley image is made with the image bounday tight around the face, while <span class="postimg"><img src="https://i.imgur.com/wJYTIBg.png" alt="wJYTIBg.png" loading="eager"></span> has a wider background. 

The first one is a native forum smiley and the second one is an image pasted in with the usual \[img\] markup. You can see that the forum software is wrapping a <span class="postimg"> tag round the externally hosted image markup. The css must be interpreted differently by different browsers on different systems. On my Debian buster system Chromium also puts a border round the external images. neutral

That's a pity but I'm not sure if anything can be done about it. 

Maybe @twoion's UTF8 characters would work better? Ah no, that was a suggestion to convert the glyph to an image, then upload it, so the same problem.

EDIT: It's the CSS rendering. I use the "Crunchbang" style, where

.postimg img

does not set a border, but the default "Hydrogen" style sets

{    border: 1px solid #787878; }

That's why I've never noticed those borders up till now. I guess on a dark theme they wouldn't be too noticable, but for non-logged-in users I don't see any way out.

Unless @twoion felt like disabling the .posting .img border on all the css themes, or just the default theme?

Last edited by johnraff (2022-03-21 04:57:45)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#11 2022-03-21 05:51:29

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 978

Re: The Smileotron

Well, at least every browser under the sun rendering things differently is a diminishing problem, now we're reduced to effectively Mozilla & Chrome.. with a truly tiny minority of other possibilities, & that diminishing as Google takes over the entire world...
I Kinda miss when Opera was different & Trident (Internet Exploder) were still things.. shortly it will be a 2 horse race with Google having all the advantages.. I'm GENUINELY sorry Microsoft apparently caved & bought into the Google ecosystem for browsers... Bring back Edge (non-chromium) if IE is fated to die...

I'm no fan of either monopolies OR duopolies.

Give me genuine multi-party competition.

Last edited by Bearded_Blunder (2022-03-21 05:57:03)


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Online

#12 2022-03-21 22:54:43

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,959
Website

Re: The Smileotron

misko_2083 wrote:

Why the forum software replaces the unicode charactes with "?" char?

Yes, I just noticed that yesterday when I tried to use a Unicode smiley. Interesting, because other Unicode characters like 日本語 go through OK.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#13 2022-03-23 01:51:40

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 978

Re: The Smileotron

misko_2083 wrote:

The Blunder man with the beard didn't like my singing.
What can I do, I'm not comfortable singing in high pitch voice like Tom Jones. big_smile

Couldn't tell you if I liked it or not, I wasn't listening.


Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me

Online

#14 2022-03-23 02:16:39

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 8,959
Website

Re: The Smileotron

@twoion, to return to the original idea of uploading images as custom smileys, I wonder if you could tweak the css so as not to add the 1px black border to images inside a <span class="postimg>? My favourite style "Crunchbang" is already like this, likewise "Air2", but the default "Hydrogen" has on Hydrogen.css line 1025:

.pun .postmsg .postimg img {

    max-width: 98%;
    vertical-align: middle;
    margin: 7px 0.5em 7px 0;
    border: 1px solid #787878;

}

Perhaps you could remove or comment out the 'border: 1px solid #787878;' line. Maybe on all themes for that matter? I'm not sure what function it serves, to be honest.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

Board footer

Powered by FluxBB