Code Monkey home page Code Monkey logo

catpix's Introduction

Catpix

Gem Version Inline docs

Renders images in the terminal.

Pokemon

It will handle most image formats (png, jpg, gif, bpm and many more). As long as ImageMagick can read it, catpix can too. By default, it will scale them down to fit the width of your terminal. You can set the same for the height of the image and also center it by providing custom options (see Usage below).

On the inside, catpix uses rmagick to read and scale images and the tco gem to map its colours to the extended 256 colour palette in the terminal. A pixel is approximated as two spaces, so you might get weird results in case your font has different proportions.

It can render full resolution photos, although it takes a while and the resolution is obviously limited. Here's a photo of some flowers in my window, straight from my phone and rendered in the terminal:

Full photo

Resolutions (new in 0.2.0)

Catpix can render images in two resolutions. If you terminal supports unicode, it will use the upper half block to dispplay one pixel. Otherwise, a pixel will be approximated as two spaces. The detection is automatic, but you can also force one or the other via options. The higher setting has four times as many pixels as the lower one. See how do they compare below:

Comparing resolutions

Usage

In the terminal

The gem will install the catpix command on your system that you can use directly from shell. To print an image simply pass the path to it as the first argument:

$ catpix pokemon.gif

Use the -c flag to center it (x for horizontal and y for vertical centering):

$ catpix panda.png -c xy

Add -w or -h to scale it down. These two options require a factor of the size of your terminal. If you want to limit the size of your image to half of your terminal window use:

$ catpix trophy.png -w 0.5 -h 0.5

And finally, if your image has any fully transparent pixels, you can specify background colour to be rendered behind and around the image. Use -b to specify the colour and -f to make it fill the margins around the image if it's centered:

$ catpix tux.png -b "#00ff00"      # RGB is fine
$ catpix tux.png -b green          # tco aliases work too
$ catpix tux.png -c xy -b green -f # fill the margins around the image too
$ catpix tux.png -c xy -r high     # enforce high resolution

In Ruby

The Ruby API consists of only a single function called print_image:

require 'catpix'

Catpix::print_image "pokemon.png",
  :limit_x => 1.0,
  :limit_y => 0,
  :center_x => true,
  :center_y => true,
  :bg => "white",
  :bg_fill => true,
  :resolution => "low"

See the documentation at RubyDoc for more detail.

More examples

UK Flag

Happy Panda

Trophy

Installation

Use gem to install Catpix from RubyGems:

$ gem install catpix

If using bundler, add this line to your application's Gemfile:

gem 'catpix'

And then execute:

$ bundle

Author

Radek Pazdera <[email protected]> radek.io

Contributing

  1. Fork it ( https://github.com/[my-github-username]/catpix/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

catpix's People

Contributors

askl56 avatar junyu-w avatar pazdera 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  avatar  avatar

catpix's Issues

error while installation

I get the following error while trying to install:

$  gem install catpix
Building native extensions.  This could take a while...
ERROR:  Error installing catpix:
	ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/rmagick-2.16.0/ext/RMagick
/usr/bin/ruby2.3 -r ./siteconf20181012-11922-hvbkdo.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/rmagick-2.16.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/rmagick-2.16.0/gem_make.out

please document the sytem lib dependencies

the gem seems to depend on libmagickcore-dev and libmagickwand-dev. I had installed the regular packages but still could not build the native extensions.

OS: Linux Mint 17.1 Rebecca

thank you.

error installing in fedora 27

when I try gem install catpix

I get this errors:

gem install catpix                                                                                              2 ↵  6529  13:28:51 
Building native extensions.  This could take a while...
ERROR:  Error installing catpix:
	ERROR: Failed to build gem native extension.

    current directory: /home/jlozadad/.gem/ruby/gems/rmagick-2.16.0/ext/RMagick
/usr/bin/ruby -r ./siteconf20180820-16460-qlq0i5.rb extconf.rb
checking for gcc... yes
checking for Magick-config... no
checking for pkg-config... yes
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
Package 'MagickCore', required by 'virtual:world', not found
checking for outdated ImageMagick version (<= 6.4.9)... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib64
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/usr/bin/$(RUBY_BASE_NAME)

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/jlozadad/.gem/ruby/extensions/x86_64-linux/2.4.0/rmagick-2.16.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/jlozadad/.gem/ruby/gems/rmagick-2.16.0 for inspection.
Results logged to /home/jlozadad/.gem/ruby/extensions/x86_64-linux/2.4.0/rmagick-2.16.0/gem_make.out

I check the log file:

find_executable: checking for gcc... -------------------- yes

--------------------

find_executable: checking for Magick-config... -------------------- no

--------------------

find_executable: checking for pkg-config... -------------------- yes

--------------------

Detected ImageMagick version: 
Can't install RMagick 2.16.0. You must have ImageMagick 6.4.9 or later.
Can't install RMagick 2.16.0. You must have ImageMagick 6.4.9 or later.

but, I have imagemagick installed

sudo dnf install ImageMagick                                                                                    1 ↵  6527  13:28:25 
Failed to synchronize cache for repo 'ippytraxx-gnome-twitch', disabling.
Last metadata expiration check: 0:00:09 ago on Mon 20 Aug 2018 01:28:25 PM EDT.
Package ImageMagick-1:6.9.9.38-1.fc27.x86_64 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!

Try using unicode characters to double the resolution

We could use only one character for the pixel split into two colours using the Unicode "Upper Half Block" character (U+2580 - ▀ and ▄) with foreground and colouring the rest with background colour.

Suggested by: Doodpants and 0x0dea

Error while install on termux

Building native extensions. This could take a while...
ERROR:  Error installing catpix:
        ERROR: Failed to build gem native extension.

    current directory: /data/data/com.termux/files/usr/lib/ruby/gems/2.5.0/gems/rmagick-2.16.0/ext/RMagick
/data/data/com.termux/files/usr/bin/ruby -r ./siteconf20190112-26739-1vvdqbd.rb extconf.rb
mkmf.rb can't find header files for ruby at /data/data/com.termux/files/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /data/data/com.termux/files/usr/lib/ruby/gems/2.5.0/gems/rmagick-2.16.0 for inspection.
Results logged to /data/data/com.termux/files/usr/lib/ruby/gems/2.5.0/extensions/aarch64-linux/2.5.0/rmagick-2.16.0/gem_make.out```


also with rmagic

Add some tests

This gem rocks, I was thinking about adding some tests (maybe rspec).
Specs will make code refactor easyer.

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.