Ruby binding of stb-image.h
Works well on windows!!! Added support for Linux (32, 64, arm)
Supports (so far):
- stbi_load (Default image loader)
gem install stbimage
gem install stbimage
Note: In Windows and in Linux the gem should work immadiately 'cause we using precompiled libs (see Usage). In macOs you have to compile the dynamic libary (.so) yourself (see Compilation).
If you want to compile the shared libary yourself, Use the instruction below (otherwise if the gem works for you than this step is unnecessary):
Download sources: stb-source (stb_image.h, stb_image.c)
Navigate to the files in terminal with
Run the command in terminal (works with macOs, linux, and linux arm):
gcc -shared -o libstb.so -fPIC stb_image.c
If nothing shows up than finally you got your own
libstb.sofile what is fully compatible with your system.
See Usage to properly load it to your program.
Precompiled shared libs (.dll, .so)
You can find it under dlls folder, but they are also included in the gem
require 'stbimage' # When you using the precompiled shared libs. Only works with linux, arm, Windows (in macOs it doesn't work) STBIMAGE.load_lib() # Although when the above function doesn't work for you for some reason (or you are using macOs), please specify arguments in .load_lib function # 1. When your own .dll, or .so libary is at the same folder as your program. Or you wanna specify relative_path to file # STBIMAGE.load_lib('your_name.so') # or # STBIMAGE.load_lib('your_folder/your_name.so') # 2. When your own .dll or .so file is somewhere in your storage, please specify absolute path # Example: # STBIMAGE.load_lib('your_name.so', '/home/user/documents/ruby_proj/dll') width = ' ' * 4 height = ' ' * 4 nr_channels = ' ' * 4 data = STBIMAGE.stbi_load("blue-poly.jpg", width, height, nr_channels, 0) puts data # You can use this data in OpenGL for instance. puts width.unpack('l') puts height.unpack('l') puts nr_channels.unpack('l')
Credit to Vaiorabbit who made the bindings of opengl into ruby! This wrapper is based on his glfw wrapper. His repo: https://github.com/vaiorabbit/ruby-opengl
stb_image.h by Sean Barret. Repo: https://github.com/nothings/stb/blob/master/stb_image.h
Copyright (c) 2021 Samuel Keresztes Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.