From c98d545c270cf0bfad7d624fc80b69ed3b7cc478 Mon Sep 17 00:00:00 2001 From: Roman Gräf Date: Sun, 29 Nov 2020 03:03:56 +0100 Subject: Initial commit --- .gitignore | 9 +++++++++ Dockerfile | 8 ++++++++ Gemfile | 13 +++++++++++++ Gemfile.lock | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE.txt | 24 ++++++++++++++++++++++++ README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ herrschwarz.png | Bin 0 -> 2487319 bytes herrschwarz.rb | 40 ++++++++++++++++++++++++++++++++++++++++ hshsh.png | Bin 0 -> 2693412 bytes views/index.erb | 15 +++++++++++++++ 10 files changed, 206 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 herrschwarz.png create mode 100644 herrschwarz.rb create mode 100644 hshsh.png create mode 100644 views/index.erb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..406faec --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ +/uploads/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dd01371 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM ruby:2.5 + +RUN bundle config --global frozen 1 +WORKDIR /usr/src/app +COPY Gemfile Gemfile.lock ./ +RUN bundle install +COPY . . +CMD ["ruby", "herrschwarz.rb"] diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7934ab1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem 'mini_magick' +gem 'chunky_png', '~> 1.3' +gem "sinatra" + +gem "rake", "~> 13.0" + +gem "minitest", "~> 5.0" + +gem "rubocop", "~> 0.80" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..1cc46e7 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,53 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.1) + chunky_png (1.3.14) + mini_magick (4.11.0) + minitest (5.14.2) + mustermann (1.1.1) + ruby2_keywords (~> 0.0.1) + parallel (1.20.1) + parser (2.7.2.0) + ast (~> 2.4.1) + rack (2.2.3) + rack-protection (2.1.0) + rack + rainbow (3.0.0) + rake (13.0.1) + regexp_parser (2.0.0) + rexml (3.2.4) + rubocop (0.93.1) + parallel (~> 1.10) + parser (>= 2.7.1.5) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8) + rexml + rubocop-ast (>= 0.6.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (1.2.0) + parser (>= 2.7.1.5) + ruby-progressbar (1.10.1) + ruby2_keywords (0.0.2) + sinatra (2.1.0) + mustermann (~> 1.0) + rack (~> 2.2) + rack-protection (= 2.1.0) + tilt (~> 2.0) + tilt (2.0.10) + unicode-display_width (1.7.0) + +PLATFORMS + x64-mingw32 + +DEPENDENCIES + chunky_png (~> 1.3) + mini_magick + minitest (~> 5.0) + rake (~> 13.0) + rubocop (~> 0.80) + sinatra + +BUNDLED WITH + 2.2.0.rc.2 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..00d2e13 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +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 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. + +For more information, please refer to \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..783b014 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# Herrschwarz + +Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/herrschwarz`. To experiment with that code, run `bin/console` for an interactive prompt. + +TODO: Delete this and the text above, and describe your gem + +## Installation + +Add this line to your application's Gemfile: + +```ruby +gem 'herrschwarz' +``` + +And then execute: + + $ bundle install + +Or install it yourself as: + + $ gem install herrschwarz + +## Usage + +TODO: Write usage instructions here + +## Development + +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. + +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/herrschwarz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/herrschwarz/blob/master/CODE_OF_CONDUCT.md). + + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). + +## Code of Conduct + +Everyone interacting in the Herrschwarz project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/herrschwarz/blob/master/CODE_OF_CONDUCT.md). diff --git a/herrschwarz.png b/herrschwarz.png new file mode 100644 index 0000000..9c304b2 Binary files /dev/null and b/herrschwarz.png differ diff --git a/herrschwarz.rb b/herrschwarz.rb new file mode 100644 index 0000000..1dd9cf7 --- /dev/null +++ b/herrschwarz.rb @@ -0,0 +1,40 @@ +require 'sinatra' +require 'chunky_png' +require 'rmagick' + +COORDS = 225, 1300 +SIGN_SIZE = 1443, 900 +IMAGE_SIZE = 1920, 2218 +OVERLAY = Magick::ImageList.new("herrschwarz.png") + +def random_file_name(ext) + (0...50).map { ('a'..'z').to_a[rand(26)] }.join + "." + ext +end + +def herrschwarzify_image(image) + background = Magick::Image.new(*IMAGE_SIZE) + canvas = Magick::Draw.new + canvas.composite *COORDS, *SIGN_SIZE, image + canvas.composite 0, 0, 0, 0, OVERLAY + canvas.draw background + background +end + +Dir.mkdir "uploads" unless Dir.exists? "uploads" + +get "/" do + erb :index +end + +post "/upload" do + return redirect "/" unless params['file'] && (tmpfile = params[:file][:tempfile]) && (name = params[:file][:filename]) + orig = Magick::ImageList.new(tmpfile.path) + transformed = herrschwarzify_image(orig) + filename = random_file_name("png") + transformed.write("uploads/#{filename}") + redirect "/uploads/#{filename}" +end + +get "/uploads/:filename" do |filename| + send_file "uploads/#{filename}", :type => :png +end diff --git a/hshsh.png b/hshsh.png new file mode 100644 index 0000000..95bcb37 Binary files /dev/null and b/hshsh.png differ diff --git a/views/index.erb b/views/index.erb new file mode 100644 index 0000000..fb6ccbd --- /dev/null +++ b/views/index.erb @@ -0,0 +1,15 @@ + + + + + + + Document + + +
+ + +
+ + \ No newline at end of file -- cgit