idi_captcha_generator 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f97ae83dadff3f8cecdeaaf0787765fbf8d6c384197e46409fe40ca9ce05522
4
- data.tar.gz: 32116ed5faa9ff35dec8e780c16da28945fbd03adb227a70bfef4aba39affc93
3
+ metadata.gz: 311d16b144c38c8e6ceeb0d324b7ed35cdc91de4c232a63354e5bc0201aafb6d
4
+ data.tar.gz: d3480b05a4f54dc884b4d59f160ca34c0fdd1e6c5451745aaec2f0d442fc1e73
5
5
  SHA512:
6
- metadata.gz: 5e29d97b07a02b583249b78eca40d8eac2c38533bf57c8bc443d35eb27b3e253c205da5848a5e634d64a01c99321f1d698c57355c91b678c8ea0b8b0123ee1c6
7
- data.tar.gz: 2c9025f7984adac2fb8520320f935202633a7c960194cb35826b89532febaf1fe2df1a1b1ff72196d45141d297151325e0f51675ec751eb0d1e0887552e2b904
6
+ metadata.gz: d53d2db5dcafd8646c7803b6ffeaf731fe0d0a1342f35e32c0189531758651aac685bf260a03005cf08c62f46b0c76edb182c963356aee10059f515bb94d8ead
7
+ data.tar.gz: 8dba16bda4c07c04faae971a7395da80422d28ef2f3a759d2ceaeb0ed7f29966a5ce2d52d4e9f6c2913d6e950b63d0cd5a94fbd410686ec58735a8a2633f2d31
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IdiCaptchaGenerator
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -1,35 +1,34 @@
1
- # lib/idi_captcha_generator.rb
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require_relative "idi_captcha_generator/version"
5
- require 'rmagick' # For image manipulation
4
+ require 'mini_magick'
6
5
 
7
6
  module CaptchaGenerator
8
7
  def self.generate_captcha
8
+ # Randomly generate a simple math question
9
9
  num1 = rand(1..10)
10
10
  num2 = rand(1..10)
11
11
  answer = num1 + num2
12
12
  question = "#{num1} + #{num2} = ?"
13
13
 
14
- image = Magick::Image.new(200, 100) {
15
- self.background_color = 'white'
16
- }
17
- draw = Magick::Draw.new
18
- draw.annotate(image, 0, 0, 0, 0, question) do
19
- draw.font = 'Helvetica'
20
- draw.fill = 'black'
21
- draw.pointsize = 32
22
- draw.gravity = Magick::CenterGravity
14
+ # Create a white canvas using MiniMagick
15
+ image = MiniMagick::Image.create('png') do |f|
16
+ f.write MiniMagick::Image.new('canvas:white', size: '200x100').to_blob
17
+ end
18
+
19
+ # Annotate the captcha text on the image
20
+ image.combine_options do |c|
21
+ c.font 'Helvetica'
22
+ c.fill 'black'
23
+ c.pointsize '32'
24
+ c.gravity 'center'
25
+ c.draw "text 0,0 '#{question}'"
23
26
  end
24
- draw.draw(image)
25
27
 
26
28
  # Save image to a temporary location
27
- image_path = Rails.root.join('tmp', "captcha_#{Time.now.to_i}.png")
29
+ image_path = File.join(Dir.tmpdir, "captcha_#{Time.now.to_i}.png")
28
30
  image.write(image_path)
29
31
 
30
- # Clean up temporary files after a certain period
31
- File.delete(image_path) if File.exist?(image_path) && Time.now - File.mtime(image_path) > 60 # 1 minute expiry
32
-
33
32
  { question: question, answer: answer, image_path: image_path }
34
33
  end
35
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idi_captcha_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Idrees Ibrahim