Coder Social home page Coder Social logo

gargron / blurhash Goto Github PK

View Code? Open in Web Editor NEW
284.0 284.0 26.0 138 KB

Encode an image as a small string that can be saved in the database, returned in API responses, and displayed as a blurred preview before the real image loads

License: MIT License

Ruby 43.97% Shell 1.40% C 54.63%

blurhash's Introduction

KISSmetrics for PHP

Build Status

KISSmetrics PHP client that doesn't overuse the singleton pattern and has a slightly better API and no built-in cron support (that's a feature). Here's how to use it:

$km = new KISSmetrics\Client('API key', KISSmetrics\Transport\Sockets::initDefault()); // Initialize

$km->identify('[email protected]')   // Identify user (always)
  ->alias('old-anonymous-cookie')  // Alias to previously anonymous user, maybe
  ->set(array('gender' => 'male')) // Set some property
  ->record('Viewed thing');        // Record an event, optionally with properties

$km->submit(); // Submit all that to KISSmetrics in one go

In case of errors this thing throws a KISSmetrics\ClientException so if you have a fire-and-forget attitude to these metrics just try/catch those. Though it's helpful when you want to make sure everything is setup correctly!

Composer

{
  "require": {
    "kissmetrics/kissmetrics-php": "~0.4.2"
  }
}

License

Licensed under the MIT license.

blurhash's People

Contributors

c960657 avatar clearlyclaire avatar dependabot[bot] avatar elcuervo avatar eregon avatar gargron avatar noellabo avatar renchap avatar tenderlove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

blurhash's Issues

Segmentation fault on ruby 3.0.4

I'm getting quite often Segmentation fault error when starting my rails app which is using blurhash. Error is present in both 0.1.6 and the master version.

/usr/src/app/vendor/bundle/ruby/3.0.0/bundler/gems/blurhash-870a34e01ce7/lib/blurhash.rb:9: [BUG] Segmentation fault at 0x00007f66600a1000
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0077 p:---- s:0404 e:000403 CFUNC :blurHashForPixels
c:0076 p:0044 s:0395 e:000394 METHOD /usr/src/app/vendor/bundle/ruby/3.0.0/bundler/gems/blurhash-870a34e01ce7/lib/blurhash.rb:9

(...)

-- Machine register context ------------------------------------------------
RIP: 0x00007f51e00a03d0 RBP: 0x00007ffcdea45050 RSP: 0x00007ffcdea44dd0
RAX: 0x0000000000000000 RBX: 0x00007f518c0dffff RCX: 0x0000000000000009
RDX: 0x0000000000000000 RDI: 0x0000000000000000 RSI: 0x00007f51e3a3b140
R8: 0x000000003d5cf53a R9: 0x0000000000000708 R10: 0x00007f51e362ec60
R11: 0x0000000000000000 R12: 0x000000000000023d R13: 0x0000000000000149
R14: 0x0000000000090948 R15: 0x0000000000000258 EFL: 0x0000000000010202

-- C level backtrace information -------------------------------------------
/usr/local/lib/libruby.so.3.0(rb_print_backtrace+0x11) [0x7f51e3e7b9ec] vm_dump.c:758
/usr/local/lib/libruby.so.3.0(rb_vm_bugreport) vm_dump.c:998
/usr/local/lib/libruby.so.3.0(rb_bug_for_fatal_signal+0xf0) [0x7f51e3c85f60] error.c:787
/usr/local/lib/libruby.so.3.0(sigsegv+0x49) [0x7f51e3dd3239] signal.c:963
/lib/x86_64-linux-gnu/libpthread.so.0(__restore_rt+0x0) [0x7f51e3b80140]
/usr/src/app/vendor/bundle/ruby/3.0.0/bundler/gems/blurhash-e71fd5de6f38/lib/blurhash_ext.so(blurHashForPixels+0x230) [0x7f51e00a03d0] encode.c:79
/usr/src/app/vendor/bundle/ruby/3.0.0/bundler/gems/blurhash-e71fd5de6f38/lib/blurhash_ext.so(blurHashForPixels) (null):0
/usr/src/app/vendor/bundle/ruby/3.0.0/bundler/gems/blurhash-e71fd5de6f38/lib/blurhash_ext.so(rb_blur_hash_for_pixels+0xaa) [0x7f51e00a0d6a] encode.c:142
/usr/local/lib/libruby.so.3.0(vm_cfp_consistent_p+0x0) [0x7f51e3e527dc] vm_insnhelper.c:2928
/usr/local/lib/libruby.so.3.0(vm_call_cfunc_with_frame) vm_insnhelper.c:2930
/usr/local/lib/libruby.so.3.0(vm_sendish+0x37f) [0x7f51e3e5d77f] vm_insnhelper.c:4529
/usr/local/lib/libruby.so.3.0(vm_exec_core+0x94) [0x7f51e3e60664] insns.def:789
/usr/local/lib/libruby.so.3.0(rb_vm_exec+0x9be) [0x7f51e3e6640e] vm.c:2171
/usr/local/lib/libruby.so.3.0(invoke_bmethod+0x14a) [0x7f51e3e66f5a] vm.c:1293
/usr/local/lib/libruby.so.3.0(vm_call0_body+0x593) [0x7f51e3e690f3] vm_insnhelper.c:2987
/usr/local/lib/libruby.so.3.0(rb_call0+0x1e5) [0x7f51e3e6b5d5] vm_eval.c:72
/usr/local/lib/libruby.so.3.0(send_internal+0xf9) [0x7f51e3e6bd19] vm_eval.c:1245
/usr/local/lib/libruby.so.3.0(vm_cfp_consistent_p+0x0) [0x7f51e3e527dc] vm_insnhelper.c:2928
/usr/local/lib/libruby.so.3.0(vm_call_cfunc_with_frame) vm_insnhelper.c:2930
/usr/local/lib/libruby.so.3.0(vm_sendish+0x37f) [0x7f51e3e5d77f] vm_insnhelper.c:4529
/usr/local/lib/libruby.so.3.0(vm_exec_core+0x94) [0x7f51e3e60664] insns.def:789
/usr/local/lib/libruby.so.3.0(rb_vm_exec+0x182) [0x7f51e3e65bd2] vm.c:2162
/usr/local/lib/libruby.so.3.0(rb_yield+0x25b) [0x7f51e3e730eb] vm.c:1263
/usr/local/lib/libruby.so.3.0(RB_FL_TEST_RAW+0x0) [0x7f51e3bf282c] array.c:2523
/usr/local/lib/libruby.so.3.0(RB_FL_ANY_RAW) ./include/ruby/internal/fl_type.h:258
/usr/local/lib/libruby.so.3.0(rb_array_len) ./include/ruby/internal/core/rarray.h:135
/usr/local/lib/libruby.so.3.0(rb_ary_each) array.c:2522
/usr/local/lib/libruby.so.3.0(vm_cfp_consistent_p+0x0) [0x7f51e3e527dc] vm_insnhelper.c:2928
/usr/local/lib/libruby.so.3.0(vm_call_cfunc_with_frame) vm_insnhelper.c:2930
/usr/local/lib/libruby.so.3.0(vm_sendish+0x37f) [0x7f51e3e5d77f] vm_insnhelper.c:4529
/usr/local/lib/libruby.so.3.0(vm_exec_core+0x103) [0x7f51e3e606d3] insns.def:770
/usr/local/lib/libruby.so.3.0(rb_vm_exec+0x182) [0x7f51e3e65bd2] vm.c:2162
/usr/local/lib/libruby.so.3.0(invoke_bmethod+0x14a) [0x7f51e3e66f5a] vm.c:1293
/usr/local/lib/libruby.so.3.0(vm_call_bmethod+0xd8) [0x7f51e3e70da8] vm_insnhelper.c:2987
/usr/local/lib/libruby.so.3.0(vm_sendish+0x37f) [0x7f51e3e5d77f] vm_insnhelper.c:4529
/usr/local/lib/libruby.so.3.0(vm_exec_core+0x94) [0x7f51e3e60664] insns.def:789
/usr/local/lib/libruby.so.3.0(rb_vm_exec+0x182) [0x7f51e3e65bd2] vm.c:2162
/usr/local/lib/libruby.so.3.0(invoke_bmethod+0x14a) [0x7f51e3e66f5a] vm.c:1293

Documentation for Minimagick

Rails 6 seems to standardise on minimagick or vips for image processing. It seems optimal to use this over RMagick in just about any case.

I'm going to explore which methods need to be used to get minimagick to export data to Blurhash in the right way, with intent to make a PR to document them after I do. My questions are:

  1. Does anyone know how to do this already, and if so, would they like to take responsibility for documenting it?
  2. Should documentation on minimagick replace (or otherwise supersede) documentation for RMagick? If so, how? Straight-up delete or just move RMagick to an addendum?

Documentation for Rails

Hello,

do you have any documentation about using this gem with Rails?

In particular:

  • How to generate a blurhash from ActiveStorage?
  • How to display the blurhash image in the HTML?

JRuby Support

this is the error I get on gem install.

creating Makefile

current directory: /home/oshan/.asdf/installs/ruby/jruby-9.2.11.1/lib/ruby/gems/shared/gems/blurhash-0.1.4/ext/blurhash
make "DESTDIR=" clean

current directory: /home/oshan/.asdf/installs/ruby/jruby-9.2.11.1/lib/ruby/gems/shared/gems/blurhash-0.1.4/ext/blurhash
make "DESTDIR="
make: *** No rule to make target '/home/oshan/.asdf/installs/ruby/jruby-9.2.11.1/lib/ruby/include/ruby/ruby.h', needed by 'encode.o'.  Stop.

make failed, exit code 2

Install fails on windows: Init_encode: symbol not defined [Ruby 3.0.4p208; bundle 2.2.33; MAKE 4.3; GCC(mingw) 8.1.0; GNU ld 2.30;]

gem install blurhash fails to complete the native compilation step.
While linking (makefile line 262), blurhash can't find symbol Init_encode
(because it doesn't exist eanywhere in the repository)

I must confess that i know very little about make/rake, so i have no idea wheather this is an issue with generating "encode-x64-mingw32.def", or if the linker somehow misunderstands what it's supposed to be doing.

Files: (no encode.so, wich is specified in Makefile as variable DLLIB)
image

Generated contents of encode-x64-mingw32.de

EXPORTS
Init_encode

Contents of makefile
Makefile.txt

Logs:

current directory: C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/blurhash-0.1.6/ext/blurhash
C:/Ruby30-x64/bin/ruby.exe -I C:/Ruby30-x64/lib/ruby/3.0.0 -r ./siteconf20220519-11088-6nj65z.rb extconf.rb
creating Makefile

current directory: C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/blurhash-0.1.6/ext/blurhash
make DESTDIR\= clean

current directory: C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/blurhash-0.1.6/ext/blurhash
make DESTDIR\=
generating encode-x64-mingw32.def
compiling encode.c
linking shared-object encode.so
C:/Ruby30-x64/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot export Init_encode: symbol not defined
collect2.exe: error:
 ld returned 1 exit status
make: *** [Makefile:262: encode.so] Error 1

make failed, exit code 2

Algorithm documentation

Would it be possible to have a better description of the algorithm itself (the rationales and core mechanisms)?. The C code is readable but don't give much information about how and why this thing works better than, for example, interpolating k pixels of the picture.

(this not an issue per se, more like an improvement)

how to display text version of image?

This looks very interesting, but I haven't been able to find any documentation on how to actually display the low resolution, text version of the image. I tried with , but that didn't seem to work for gif, jpg or png.

Cannot open shared object file

Hello, I'm having the following error in my CI, right after running bundle install:

LoadError: Could not open library '/builds/my-project/vendor/bundle/ruby/3.1.0/gems/blurhash-0.1.6/lib/../ext/blurhash/encode.so': /builds/my-project/vendor/bundle/ruby/3.1.0/gems/blurhash-0.1.6/lib/../ext/blurhash/encode.so: cannot open shared object file: No such file or directory

I'm using Gitlab CI, with Ruby 3.1.3 and Blurhash 0.1.6.

I'm not sure why this happens since I apparently didn't change anything on my side, so I'm posting here in case other people have the same issue. I'll reply if I find a fix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.