release_image 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 876de90416bb7a1f25b934f5dcfdc7e6a9b111742d04540bb0c1f001d6c71671
4
+ data.tar.gz: 515ceb09324e5984b6e9f29b4716418f3e7bc3d7ac6b11ba9ae1e7096c26bcf6
5
+ SHA512:
6
+ metadata.gz: cc2c9b4d29e5fc7d0bb84c0adff43ab064d361f8ae9d81adf96c5dc91da6fdda8ff1b107695cf952419cba27d638a208dbbf74c299b44f6fb3ff6da10bc4811d
7
+ data.tar.gz: 61ea6e716099efae97a2119b971dc53189df658bae349739730ff2614599c6f1f0d5203f6d5cd9ccfc0a7e00957cc8067080de68522c335e6e73d689548036d5
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Style/Documentation:
16
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.3.0] - 2023-11-21
4
+
5
+ - Add option to use previously downloaded images
6
+
7
+ ## [0.2.0] - 2023-07-20
8
+
9
+ - Remove compose option
10
+ - Improve image comparison in tests
11
+ - Update readme and examples
12
+
13
+ ## [0.1.0] - 2023-06-20
14
+
15
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at info@effectiva.hr. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in release_image.gemspec
6
+ gemspec
7
+
8
+ gem "dotenv"
9
+ gem "minitest"
10
+ gem "mocha"
11
+ gem "rake"
12
+ gem "rubocop"
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ release_image (0.3.1)
5
+ down
6
+ mini_magick
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.6)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ ast (2.4.2)
14
+ dotenv (2.8.1)
15
+ down (5.4.1)
16
+ addressable (~> 2.8)
17
+ json (2.6.3)
18
+ mini_magick (4.12.0)
19
+ minitest (5.18.0)
20
+ mocha (2.0.4)
21
+ ruby2_keywords (>= 0.0.5)
22
+ parallel (1.23.0)
23
+ parser (3.2.2.3)
24
+ ast (~> 2.4.1)
25
+ racc
26
+ public_suffix (5.0.4)
27
+ racc (1.7.1)
28
+ rainbow (3.1.1)
29
+ rake (13.0.6)
30
+ regexp_parser (2.8.1)
31
+ rexml (3.2.5)
32
+ rubocop (1.52.1)
33
+ json (~> 2.3)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.2.2.3)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml (>= 3.2.5, < 4.0)
39
+ rubocop-ast (>= 1.28.0, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 2.4.0, < 3.0)
42
+ rubocop-ast (1.29.0)
43
+ parser (>= 3.2.1.0)
44
+ ruby-progressbar (1.13.0)
45
+ ruby2_keywords (0.0.5)
46
+ unicode-display_width (2.4.2)
47
+
48
+ PLATFORMS
49
+ arm64-darwin-21
50
+ arm64-darwin-22
51
+ ruby
52
+ x86_64-linux
53
+
54
+ DEPENDENCIES
55
+ dotenv
56
+ minitest
57
+ mocha
58
+ rake
59
+ release_image!
60
+ rubocop
61
+
62
+ BUNDLED WITH
63
+ 2.3.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Effectiva studio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Release Image
2
+
3
+ ![release_1_0_0](https://github.com/EffectivaStudio/release_image/assets/66572/e73724ee-3da7-4769-adcf-cdf26816d9d0)
4
+
5
+ The Release Image gem is a powerful tool designed specifically for creating captivating cover images for release posts or notices in your application. It streamlines the process of generating visually appealing images by seamlessly incorporating your app's logo, version, and release date. Additionally, it provides the ability to fetch random images from the extensive collection available on the [Unsplash](https://unsplash.com/) service.
6
+
7
+ ## Features
8
+
9
+ - 🌟 Effortlessly create stunning cover images for release posts or notices
10
+ - 🌟 Seamlessly integrate your app's logo, version, and release date into the images
11
+ - 🌟 Utilize the vast collection of Unsplash to obtain random images
12
+ - 🌟 Customize various aspects of the image generation process
13
+
14
+ Enjoy creating eye-catching and unique cover images for your release posts with the Release Image gem!
15
+
16
+ ## Installation
17
+
18
+ Install the gem and add it to the application's Gemfile by executing:
19
+
20
+ source "https://rubygems.pkg.github.com/effectivastudio" do
21
+ gem "release_image", require: false
22
+ end
23
+
24
+ ## Usage
25
+
26
+ Example `bin/release_image` script:
27
+
28
+ ```rb
29
+ #!/usr/bin/env ruby
30
+
31
+ require "dotenv/load"
32
+ require "optparse"
33
+ require "colorize"
34
+ require "release_image"
35
+
36
+ APP_ROOT = File.expand_path("..", __dir__)
37
+
38
+ options = {}
39
+
40
+ OptionParser.new do |opts|
41
+ opts.banner = "Usage: bin/release_image version [date] [options]"
42
+
43
+ opts.on("--skip-download", "Skip downloading a random image and use a previously downloaded image instead.") do
44
+ options[:skip_download] = true
45
+ end
46
+
47
+ opts.on("-h", "--help", "Prints this help") do
48
+ puts opts
49
+ exit
50
+ end
51
+ end.parse!
52
+
53
+ # Get api key at:
54
+ # https://unsplash.com/oauth/applications
55
+ #
56
+ # keywords - An array of keywords that can be used to filter the random image
57
+ # folder_path - The destination folder where the generated images will be saved
58
+ # logo_path - The path to your app's logo image
59
+ # seasons - Generate images based on the current season of the year
60
+
61
+ ReleaseImage.config.api_key = ENV.fetch("UNSPLASH_API_KEY")
62
+ ReleaseImage.config.keywords = %w[nature wallpaper]
63
+ ReleaseImage.config.folder_path = File.join(APP_ROOT, "tmp/release_image")
64
+ ReleaseImage.config.logo_path = File.join(APP_ROOT, "app/assets/images/logo/release_logo.png")
65
+ ReleaseImage.config.seasons = true
66
+
67
+ version = ARGV[0]
68
+ date = ARGV[1]
69
+
70
+ abort("Please provide a release version".red) unless version
71
+
72
+ puts ReleaseImage.generate(version: version, date: date, skip_download: options[:skip_download]).green
73
+ ```
74
+
75
+ ### Use existing image
76
+
77
+ Sometimes you may want to skip downloading a random image and use a previously downloaded image instead. This can be
78
+ achieved by setting the `skip_download` option to `true`. Image is downloaded by default and saved to the `folder_path`
79
+ directory as `image.jpg`.
80
+
81
+ ```rb
82
+ ReleaseImage.generate(version: version, date: date, skip_download: true)
83
+ ```
84
+
85
+ ## Development
86
+
87
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
88
+
89
+ To install this gem onto your local machine, run `bundle exec rake install:local`. 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.pkg.github.com](https://rubygems.pkg.github.com/effectivastudio).
90
+
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/EffectivaStudio/release_image. 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/EffectivaStudio/release_image/blob/main/CODE_OF_CONDUCT.md).
95
+
96
+
97
+ ## License
98
+
99
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
100
+
101
+ ## Code of Conduct
102
+
103
+ Everyone interacting in the Release Image project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/EffectivaStudio/release_image/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ReleaseImage
4
+ VERSION = "0.3.1"
5
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mini_magick"
4
+ require "down"
5
+ require "fileutils"
6
+ require "pathname"
7
+
8
+ require_relative "release_image/version"
9
+
10
+ module ReleaseImage
11
+ class Error < StandardError; end
12
+
13
+ class Config
14
+ attr_accessor :api_key, :folder_path, :logo_path, :keywords, :seasons
15
+
16
+ def initialize
17
+ @api_key = nil
18
+ @folder_path = nil
19
+ @logo_path = nil
20
+ @keywords = []
21
+ @seasons = true
22
+ end
23
+ end
24
+
25
+ class Generator
26
+ BASE_URL = "https://api.unsplash.com/photos/random"
27
+
28
+ def initialize(version:, date: nil, skip_download: false)
29
+ @version = version
30
+ @date = date ? Date.parse(date) : Date.today
31
+
32
+ @skip_download = skip_download
33
+
34
+ @folder_path = ReleaseImage.config.folder_path
35
+ @logo_path = ReleaseImage.config.logo_path
36
+ @keywords = ReleaseImage.config.keywords
37
+ @api_key = ReleaseImage.config.api_key
38
+ @seasons = ReleaseImage.config.seasons
39
+ end
40
+
41
+ def generate
42
+ create_folder
43
+ download_image unless @skip_download
44
+ create_release_image
45
+ end
46
+
47
+ def create_folder
48
+ FileUtils.mkdir_p(@folder_path) unless File.directory?(@folder_path)
49
+ end
50
+
51
+ def download_image
52
+ uri = URI(url)
53
+ response = Net::HTTP.get_response(uri)
54
+
55
+ data = JSON.parse(response.body)
56
+ image_url = data["urls"]["regular"]
57
+ image = Down.download(image_url)
58
+ File.binwrite(image_path, image.read)
59
+ end
60
+
61
+ def create_release_image
62
+ image = MiniMagick::Image.open(image_path)
63
+
64
+ resize_image(image)
65
+ add_background_and_text(image)
66
+ result = add_logo(image)
67
+
68
+ result.write release_image_path
69
+
70
+ release_image_path
71
+ end
72
+
73
+ def release_image_path
74
+ underscored_version = @version.tr(".", "_")
75
+ "#{@folder_path}/release_#{underscored_version}.png"
76
+ end
77
+
78
+ def resize_image(image)
79
+ image.resize "1920x1200^"
80
+ image.gravity "center"
81
+ image.extent "1920x1200"
82
+ end
83
+
84
+ def add_background_and_text(image) # rubocop:disable Metrics/MethodLength
85
+ image.combine_options do |cmd|
86
+ cmd.geometry "+0+0"
87
+ cmd.gravity "center"
88
+
89
+ cmd.fill "rgba(0, 0, 0, 0.5)"
90
+ cmd.draw "rectangle 0,0 #{image.width},#{image.height}"
91
+
92
+ cmd.fill "white"
93
+ cmd.font "Helvetica"
94
+
95
+ cmd.pointsize 80
96
+ cmd.draw "text 0, -100 'v#{@version}'"
97
+
98
+ cmd.pointsize 60
99
+ cmd.draw "text 0, -10 '#{@date.strftime("%d. %B %Y.")}'"
100
+ end
101
+ end
102
+
103
+ def add_logo(image)
104
+ logo = MiniMagick::Image.open(@logo_path)
105
+
106
+ image.composite(logo) do |c|
107
+ c.geometry "+#{(image.width / 2) - (logo.width / 2)}+300"
108
+ end
109
+ end
110
+
111
+ def image_path
112
+ "#{@folder_path}/image.jpg"
113
+ end
114
+
115
+ def url
116
+ "#{BASE_URL}?query=#{query}&client_id=#{@api_key}"
117
+ end
118
+
119
+ def query
120
+ result = @keywords
121
+ result += [season] if @seasons
122
+ result.join(" ")
123
+ end
124
+
125
+ def season
126
+ case @date.strftime("%m").to_i
127
+ when 3..5 then "Spring"
128
+ when 6..8 then "Summer"
129
+ when 9..11 then "Autumn"
130
+ else "Winter"
131
+ end
132
+ end
133
+
134
+ def api_key
135
+ ReleaseImage.config.api_key
136
+ end
137
+ end
138
+
139
+ def self.config
140
+ @config ||= ReleaseImage::Config.new
141
+ end
142
+
143
+ def self.generate(version:, date: nil, skip_download: false)
144
+ Generator.new(version: version, date: date, skip_download: skip_download).generate
145
+ end
146
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: release_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Effectiva studio
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: down
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mini_magick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: It genrates a random image for release using Unsplash API
42
+ email:
43
+ - info@effectiva.hr
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rubocop.yml"
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/release_image.rb
57
+ - lib/release_image/version.rb
58
+ homepage: https://github.com/EffectivaStudio/release_image
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ homepage_uri: https://github.com/EffectivaStudio/release_image
63
+ source_code_uri: https://github.com/EffectivaStudio/release_image
64
+ changelog_uri: https://github.com/EffectivaStudio/release_image/blob/main/CHANGELOG
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.6.0
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.4.18
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Generate random image for release
84
+ test_files: []