Skip to content

Commit

Permalink
Merge pull request #7 from imdrasil/bugfix/remove-log-dependency
Browse files Browse the repository at this point in the history
Remove log dependency
  • Loading branch information
imdrasil authored Jun 24, 2021
2 parents 522f2bd + 3808ca7 commit 6bd96a1
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 132 deletions.
20 changes: 20 additions & 0 deletions .github/install_imagemagick.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set -exo pipefail

sudo apt-get remove imagemagick && sudo apt-get autoremove

sudo apt-get install build-essential

wget "http://www.imagemagick.org/download/ImageMagick.tar.gz"
mkdir ImageMagick
tar xzvf ImageMagick.tar.gz -C ./ImageMagick

cd ImageMagick/*/
./configure

make

sudo make install

sudo ldconfig /user/local/lib

convert --version
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
schedule:
- cron: "0 7 * * 1"

jobs:
test:
strategy:
fail-fast: false

runs-on: ubuntu-latest

steps:
- name: Install Crystal
uses: oprypin/install-crystal@v1

- name: Donwload sources
uses: actions/checkout@v2

- name: Check formatting
run: crystal tool format --check

- name: Install dependencies
run: shards install --ignore-crystal-version

- name: Run linter
run: ./bin/ameba

- name: Install ImageMagick
run: bash .github/install_imagemagick.sh

- name: Run specs
run: make seq
22 changes: 0 additions & 22 deletions .travis.install_imagemagick.sh

This file was deleted.

9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add this to your application's `shard.yml`:
dependencies:
crymagick:
github: imdrasil/crymagick
version: 0.2.0
version: 0.2.2
```
## Requirements
Expand Down
9 changes: 6 additions & 3 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name: crymagick
version: 0.2.0
version: 0.2.2

authors:
- Roman Kalnytskyi <moranibaca@gmail.com>

crystal: 0.35.1
crystal: 1.0.0

license: MIT
development_dependencies:
minitest:
github: ysbaddaden/minitest.cr
version: 0.5.1
version: "1.0.1"
ameba:
github: crystal-ameba/ameba
version: "= 0.14.3"
38 changes: 19 additions & 19 deletions spec/crymagick/image_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ describe CryMagick::Image do

describe ".import_pixels" do
let(:dimensions) { {325, 200} }
let(:depth) { 16 } # 16 bits (2 bytes) per pixel
let(:map) { "gray" }
let(:pixels) { Array(Int16).new(dimensions[0] * dimensions[1]) { |i| (i / 2).to_i16 } }
let(:depth) { 16 } # 16 bits (2 bytes) per pixel
let(:map) { "gray" }
let(:pixels) { Array(Int16).new(dimensions[0] * dimensions[1]) { |i| (i / 2).to_i16 } }

it "can import pixels with default format" do
image = described_class.import_pixels(pixels, dimensions[0], dimensions[1], depth, map)
Expand Down Expand Up @@ -147,11 +147,11 @@ describe CryMagick::Image do
describe "#get_pixels" do
@pix : Array(Array(CryMagick::Image::Pixel))?

let(:magenta) { {255, 0, 255} }
let(:gray) { {128, 128, 128} }
let(:green) { { 0, 255, 0} }
let(:cyan) { { 0, 255, 255} }
let(:pix) { subject.get_pixels }
let(:magenta) { {255, 0, 255} }
let(:gray) { {128, 128, 128} }
let(:green) { {0, 255, 0} }
let(:cyan) { {0, 255, 255} }
let(:pix) { subject.get_pixels }
let(:subject) { described_class.open(image_path(:rgb)) }

describe "without modifications" do
Expand All @@ -161,15 +161,15 @@ describe CryMagick::Image do
end
end

it("returns a magenta pixel") { expect(pix[3][3] ).must_equal(magenta) }
it("returns a gray pixel") { expect(pix[-4][-4]).must_equal(gray) }
it("returns a green pixel") { expect(pix[3][-4] ).must_equal(green) }
it("returns a cyan pixel") { expect(pix[-4][3] ).must_equal(cyan) }
it("returns a magenta pixel") { expect(pix[3][3]).must_equal(magenta) }
it("returns a gray pixel") { expect(pix[-4][-4]).must_equal(gray) }
it("returns a green pixel") { expect(pix[3][-4]).must_equal(green) }
it("returns a cyan pixel") { expect(pix[-4][3]).must_equal(cyan) }
end

describe "after cropping" do
let(:cols) { 10 }
let(:rows) { 6 }
let(:cols) { 10 }
let(:rows) { 6 }

before { subject.crop "#{cols}x#{rows}+3+3" }

Expand All @@ -183,10 +183,10 @@ describe CryMagick::Image do
end
end

it("returns a magenta pixel") { expect(pix[0][0] ).must_equal(magenta)}
it("returns a gray pixel") { expect(pix[-1][-1]).must_equal(gray) }
it("returns a cyan pixel") { expect(pix[-1][0] ).must_equal(cyan) }
it("returns a green pixel") { expect(pix[0][-1] ).must_equal(green) }
it("returns a magenta pixel") { expect(pix[0][0]).must_equal(magenta) }
it("returns a gray pixel") { expect(pix[-1][-1]).must_equal(gray) }
it("returns a cyan pixel") { expect(pix[-1][0]).must_equal(cyan) }
it("returns a green pixel") { expect(pix[0][-1]).must_equal(green) }
end

describe "after resizing and desaturating" do
Expand Down Expand Up @@ -489,7 +489,7 @@ describe CryMagick::Image do
describe "#combine_options" do
it "chains multiple options and executes them in one command" do
expect_to_change(->{ subject.dimensions }, to: {20, 30}) do
subject.combine_options { |c| c.resize "20x30!" }
subject.combine_options(&.resize("20x30!"))
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/crymagick/shell_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe Shell do

describe "#run" do
it "returns stdout, stderr and status" do
output = subject.run(%w[echo "asd"])
output = subject.run(["echo", %("asd")])
expect([output[0].to_s, output[1].to_s, output[2]]).must_equal ["asd\n", "", 0]
end

Expand Down Expand Up @@ -35,19 +35,19 @@ describe Shell do
stderr = stderr.to_s

expect(stdout).must_equal ""
expect(stderr).must_match("unable to open image `foo'")
expect(stderr).must_match(/unable to open image [`']foo'/)
expect(status).must_equal 256
end

it "handles larger output" do
# Timeout.timeout(1) do
stdout, a1, a2 = subject.execute(["convert", "#{image_path(:gif)}", "-"])
stdout = subject.execute(["convert", "#{image_path(:gif)}", "-"])[0]
expect(stdout.to_s).must_match("GIF")
# end
end

it "returns an appropriate response when command wasn't found" do
stdout, stderr, code = subject.execute(%w[unexisting command])
code = subject.execute(%w[unexisting command])[2]
expect(code).must_equal 32512
end

Expand All @@ -66,7 +66,7 @@ describe Shell do
# end

it "doesn't break on spaces" do
stdout, a1, a2 = subject.execute(["identify", "-format", "%w %h", image_path])
stdout = subject.execute(["identify", "-format", "%w %h", image_path])[0]
expect(stdout.to_s).must_match(/\d+ \d+/)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/crymagick/tool_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ describe CryMagick::Tool do
it "doesn't raise errors when false is passed to the constructor" do
subject.help

CryMagick::Tool::Identify.build({:whiny => false}) { |b| b.help }
CryMagick::Tool::Identify.build({:whiny => false}, &.help)
end
end
59 changes: 30 additions & 29 deletions spec/support/helper.cr
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
module Helper
def image_path(type = :default)
def image_path(type = :default) # ameba:disable Metrics/CyclomaticComplexity
if type != :jpg_without_extension
name = case type
when :default, :jpg
"default.jpg"
when :png
"engine.png"
when :animation, :gif
"animation.gif"
when :exif
"exif.jpg"
when :empty_identity_line
"empty_identity_line.png"
when :badly_encoded_line
"badly_encoded_line.jpg"
when :not
"not_an_image.cr"
when :colon
"with:colon.jpg"
when :clipping_path
"clipping_path.jpg"
when :rgb
"rgb.png"
when :rgb_tmp
"rgb_tmp.png"
when :get_pixels
"get_pixels.png"
else
raise "Image #{type} doesn't exist"
end
name =
case type
when :default, :jpg
"default.jpg"
when :png
"engine.png"
when :animation, :gif
"animation.gif"
when :exif
"exif.jpg"
when :empty_identity_line
"empty_identity_line.png"
when :badly_encoded_line
"badly_encoded_line.jpg"
when :not
"not_an_image.cr"
when :colon
"with:colon.jpg"
when :clipping_path
"clipping_path.jpg"
when :rgb
"rgb.png"
when :rgb_tmp
"rgb_tmp.png"
when :get_pixels
"get_pixels.png"
else
raise "Image #{type} doesn't exist"
end
File.join("spec", "fixtures", name)
else
path = random_path
Expand Down
2 changes: 1 addition & 1 deletion src/crymagick.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ require "./crymagick/errors"
require "./crymagick/*"

module CryMagick
VERSION = "0.2.0"
VERSION = "0.2.2"
end
36 changes: 7 additions & 29 deletions src/crymagick/configuration.cr
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
require "logger"

module CryMagick
module Configuration
# [logger, Logger?, nil]
macro class_property(name, type, default)
{% name = name.id %}

@@{{name}} : {{type}} = {{default}}

def self.{{name}}
@@{{name}}
end

def self.{{name}}=(value : {{type}})
@@{{name}} = value
end
end

{% for option in [
["cli", Symbol, :imagemagick],
["processor", Symbol, :mogrify],
["cli_path", String, ""],
["processor_path", String, "/usr/bin/mogrify"],
["whiny", Bool, true],
["validate_on_write", Bool, true],
["validate_on_create", Bool, true],
] %}

class_property({{option[0]}}, {{option[1]}}, {{option[2]}})
{% end %}
class_property cli = :imagemagick,
processor = :mogrify,
cli_path = "",
processor_path = "/usr/bin/mogrify",
whiny = true,
validate_on_write = true,
validate_on_create = true

def self.configure(&block)
yield self
Expand Down
Loading

0 comments on commit 6bd96a1

Please sign in to comment.