cafe_buy_duo 0.1.37 → 0.1.39

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cafe_buy_duo.rb +160 -52
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d1fbf0831bc2c239808b970689f328a8bcce69f7704e1494f4c2220a3c7bec8
4
- data.tar.gz: 317cac4913eb831b70d4701dd2382963c80e772192f9be163e71b51482b527b2
3
+ metadata.gz: fb2ff3d45a7a4741dc8f2832caf344eef733f7091f407596be679349b70bcd3a
4
+ data.tar.gz: bfeece7521759fc56fd83ae41992f66239e182859ac8109afba02f44eee2391f
5
5
  SHA512:
6
- metadata.gz: bec8d0d0604b46ff383ae9475fae59ad4b4c0381a352ce6529e2f918519e44cd166b59fb7eabb3c77229875d7c256639317bbafb3957db772dcf23edd039a204
7
- data.tar.gz: 0ee0dbcb27a000b17792a117d58d56d97bc5b524e094252991e80b110656aa31a1b25f545cf0650283d82930cce01ebc6ed000567237735a1abb44c8d96b3fbc
6
+ metadata.gz: 9668239becff0fd5b4bb3552dd891f2f271f1591c985a842fad075c15622901f8cb7ae3df97d25727febd712eab8cf3aa62e310cab6d1fb715c749a3381a972c
7
+ data.tar.gz: f1b110ee2f7f7a8d4c2c8900baf684dae5655173a1059b929b70afe945a51148c01e318884d75e99cf9505aa830a1b1d20e956e4428eabe9f86523ca37edee2f
data/lib/cafe_buy_duo.rb CHANGED
@@ -18,6 +18,7 @@ require 'digest'
18
18
  require 'auto_click'
19
19
  require 'rainbow/refinement'
20
20
  require 'httpclient'
21
+ require 'win32ole'
21
22
  include AutoClickMethods
22
23
  using Rainbow
23
24
  include Glimmer
@@ -242,8 +243,38 @@ end
242
243
  class Naver
243
244
  def initialize
244
245
  @seed = 1
246
+ kill_selenium_chrome #기존 창 모두 닫는 명령
247
+ sleep(1)
245
248
  end
246
249
 
250
+ def kill_selenium_chrome #기존 창 모두 닫는 코드
251
+ wmi = WIN32OLE.connect("winmgmts://")
252
+ chrome_procs = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'chrome.exe'")
253
+
254
+ chrome_procs.each do |proc|
255
+ cmd = proc.CommandLine
256
+ if cmd && cmd.include?("user-data-dir=C:/naver_cookie")
257
+ puts "→ 크롬 창 초기화: PID #{proc.ProcessId}"
258
+ begin
259
+ proc.Terminate
260
+ rescue
261
+ #puts "→ 이미 종료된 프로세스: #{proc.ProcessId}"
262
+ end
263
+ end
264
+ end
265
+
266
+ # chromedriver도 같이 종료
267
+ chromedrivers = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'chromedriver.exe'")
268
+ chromedrivers.each do |proc|
269
+ puts "→ 크롬 창 초기화: PID #{proc.ProcessId}"
270
+ begin
271
+ proc.Terminate
272
+ rescue
273
+ #puts "→ 이미 종료된 chromedriver: #{proc.ProcessId}"
274
+ end
275
+ end
276
+ end
277
+
247
278
 
248
279
  def chrome_setup(user_id, proxy)
249
280
  naver_cookie_dir = "C:/naver_cookie"
@@ -2483,52 +2514,106 @@ class Wordpress
2483
2514
  img = Magick::Image.read('./image/memory.png').first
2484
2515
  width = img.columns
2485
2516
  height = img.rows
2486
- begin
2487
- if @data['image_type'][0].checked? or @data['image_type'][2].checked?
2488
- img.resize!(w, w*(height.to_f/width.to_f))
2489
- else
2490
- img.resize!(w, w)
2517
+
2518
+ # '원본' 선택된 경우, 리사이징을 하지 않고 원본 이미지를 그대로 반환
2519
+ if w == 'original'
2520
+ return img # 원본 이미지 그대로 반환
2521
+ else
2522
+ begin
2523
+ if @data['image_type'][0].checked? or @data['image_type'][2].checked?
2524
+ # 비율을 맞추어 리사이징
2525
+ img.resize!(w, w * (height.to_f / width.to_f))
2526
+ else
2527
+ # 정사각형으로 리사이징
2528
+ img.resize!(w, w)
2529
+ end
2530
+ rescue
2531
+ img.resize!(w, w) # 예외 처리 시에도 리사이징
2491
2532
  end
2492
- rescue
2493
- img.resize!(w, w)
2494
2533
  end
2534
+
2535
+ # 리사이징된 이미지 저장
2495
2536
  img.write('./image/memory.png')
2496
2537
  end
2497
2538
 
2539
+ def wrap_text_to_fit(draw, text, max_width, max_height, font_path, initial_size)
2540
+ size = initial_size
2541
+ draw.font = font_path
2542
+
2543
+ loop do
2544
+ draw.pointsize = size
2545
+ words = text.chars # 글자 단위로 자름 (한국어 기준)
2546
+ lines = []
2547
+ line = ""
2548
+
2549
+ words.each do |char|
2550
+ test_line = line + char
2551
+ metrics = draw.get_type_metrics(test_line)
2552
+ if metrics.width > max_width
2553
+ lines << line
2554
+ line = char
2555
+ else
2556
+ line = test_line
2557
+ end
2558
+ end
2559
+ lines << line unless line.empty?
2560
+
2561
+ line_height = draw.get_type_metrics("가").height
2562
+ total_height = line_height * lines.size
2563
+
2564
+ # 세로 초과 안 하면 성공
2565
+ if total_height <= max_height || size <= 10
2566
+ return [lines.join("\n"), size]
2567
+ else
2568
+ size -= 2
2569
+ end
2570
+ end
2571
+ end
2572
+
2573
+
2498
2574
  def image_text(text1, text2)
2499
2575
  begin
2500
2576
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
2501
- font = Dir.entries('./fonts')
2502
- img = Magick::Image.read('./image/memory.png').first
2503
- text = Magick::Draw.new
2577
+ font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
2578
+ font2 = './fonts/' + font_files.sample
2504
2579
  color2 = color.sample
2505
- font2 = './fonts/'+font.sample
2506
- message = text1.to_s+"\n"+text2.to_s
2580
+
2581
+ img = Magick::Image.read('./image/memory.png').first
2582
+ draw = Magick::Draw.new
2583
+
2584
+ raw_message = "#{text1}\n#{text2}".strip
2585
+ max_width = img.columns * 0.85
2586
+ max_height = img.rows * 0.6
2587
+
2507
2588
  begin
2508
2589
  size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
2509
2590
  rescue
2510
2591
  size = 30
2511
2592
  end
2593
+
2594
+ wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
2595
+
2512
2596
  if @data['이미지설정']['글자그림자'].checked?
2513
- img.annotate(text, 0,0, +3,+3, message) do
2514
- text.gravity = Magick::CenterGravity
2515
- text.pointsize = size
2516
- text.fill = '#000000'
2517
- text.font = font2
2597
+ img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
2598
+ draw.gravity = Magick::CenterGravity
2599
+ draw.pointsize = adjusted_size
2600
+ draw.fill = '#000000'
2601
+ draw.font = font2
2518
2602
  end
2519
2603
  end
2520
-
2521
- img.annotate(text, 0,0,0,0, message) do
2522
- text.gravity = Magick::CenterGravity
2523
- text.pointsize = size
2604
+
2605
+ draw2 = Magick::Draw.new
2606
+ img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
2607
+ draw2.gravity = Magick::CenterGravity
2608
+ draw2.pointsize = adjusted_size
2609
+ draw2.fill = color2
2610
+ draw2.font = font2
2524
2611
  if @data['이미지설정']['글자테두리'].checked?
2525
- text.stroke_width = 2
2526
- text.stroke = '#000000'
2612
+ draw2.stroke_width = 2
2613
+ draw2.stroke = '#000000'
2527
2614
  end
2528
- text.fill = color2
2529
- text.font = font2
2530
2615
  end
2531
-
2616
+
2532
2617
  img.write('./image/memory.png')
2533
2618
  rescue
2534
2619
  puts '이미지 폰트 불러오기 오류 재시도...'
@@ -2562,23 +2647,30 @@ class Wordpress
2562
2647
  else
2563
2648
  auto_image()
2564
2649
  end
2565
-
2566
- image_size = [480,740,650,550,480]
2650
+
2651
+ # '원본'을 포함한 이미지 크기 옵션 추가
2652
+ image_size = [480, 740, 650, 550, 480, 'original']
2567
2653
  size = 0
2568
- for n in 0..4
2654
+
2655
+ for n in 0..5 # 0부터 5까지 반복, '원본' 옵션까지 포함
2569
2656
  if @data['image_size'][n].checked?
2570
- if n == 0
2571
- size = image_size.sample
2657
+ if n == 5 # '원본'이 선택되었을 경우
2658
+ size = 'original'
2659
+ elsif n == 0
2660
+ size = image_size.sample # 랜덤 선택
2572
2661
  else
2573
2662
  size = image_size[n]
2574
2663
  end
2575
2664
  end
2576
2665
  end
2666
+
2667
+ # '원본'이 선택되지 않았다면 기본 값 설정
2577
2668
  if size == 0
2578
2669
  size = 480
2579
2670
  end
2671
+
2672
+ change_image_size(size) # 크기 변경 함수 호출
2580
2673
 
2581
- change_image_size(size)
2582
2674
 
2583
2675
  if @data['이미지설정']['필터사용'].checked?
2584
2676
  image_filter()
@@ -2586,33 +2678,33 @@ class Wordpress
2586
2678
 
2587
2679
  if @data['이미지설정']['글자삽입1'].checked?
2588
2680
  if @data['이미지설정']['이미지글자1'].length == 0
2589
- image_text_path1 = ''
2590
- else
2591
- if @data['이미지설정']['글자랜덤'].checked?
2592
- image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2681
+ image_text_path1 = ''
2593
2682
  else
2594
- image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2595
- @image_text_soon1 += 1
2596
- if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2597
- @image_text_soon1 = 0
2598
- end
2599
- end
2683
+ if @data['이미지설정']['글자랜덤'].checked?
2684
+ image_text_path1 = @data['이미지설정']['이미지글자1'].sample
2685
+ else
2686
+ image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
2687
+ @image_text_soon1 += 1
2688
+ if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
2689
+ @image_text_soon1 = 0
2690
+ end
2691
+ end
2600
2692
  end
2601
2693
  end
2602
2694
 
2603
2695
  if @data['이미지설정']['글자삽입2'].checked?
2604
2696
  if @data['이미지설정']['이미지글자2'].length == 0
2605
- image_text_path2 = ''
2697
+ image_text_path2 = ''
2606
2698
  else
2607
- if @data['이미지설정']['글자랜덤'].checked?
2608
- image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2609
- else
2610
- image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2611
- @image_text_soon2 += 1
2612
- if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2613
- @image_text_soon2 = 0
2614
- end
2615
- end
2699
+ if @data['이미지설정']['글자랜덤'].checked?
2700
+ image_text_path2 = @data['이미지설정']['이미지글자2'].sample
2701
+ else
2702
+ image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
2703
+ @image_text_soon2 += 1
2704
+ if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
2705
+ @image_text_soon2 = 0
2706
+ end
2707
+ end
2616
2708
  end
2617
2709
  end
2618
2710
 
@@ -5029,6 +5121,7 @@ class Wordpress
5029
5121
  @data['image_size'][2].checked = false
5030
5122
  @data['image_size'][3].checked = false
5031
5123
  @data['image_size'][4].checked = false
5124
+ @data['image_size'][5].checked = false
5032
5125
  end
5033
5126
  }
5034
5127
  }
@@ -5039,6 +5132,7 @@ class Wordpress
5039
5132
  @data['image_size'][2].checked = false
5040
5133
  @data['image_size'][3].checked = false
5041
5134
  @data['image_size'][4].checked = false
5135
+ @data['image_size'][5].checked = false
5042
5136
  end
5043
5137
  }
5044
5138
  }
@@ -5049,6 +5143,7 @@ class Wordpress
5049
5143
  @data['image_size'][0].checked = false
5050
5144
  @data['image_size'][3].checked = false
5051
5145
  @data['image_size'][4].checked = false
5146
+ @data['image_size'][5].checked = false
5052
5147
  end
5053
5148
  }
5054
5149
  }
@@ -5059,6 +5154,7 @@ class Wordpress
5059
5154
  @data['image_size'][2].checked = false
5060
5155
  @data['image_size'][0].checked = false
5061
5156
  @data['image_size'][4].checked = false
5157
+ @data['image_size'][5].checked = false
5062
5158
  end
5063
5159
  }
5064
5160
  }
@@ -5069,6 +5165,18 @@ class Wordpress
5069
5165
  @data['image_size'][2].checked = false
5070
5166
  @data['image_size'][3].checked = false
5071
5167
  @data['image_size'][0].checked = false
5168
+ @data['image_size'][5].checked = false
5169
+ end
5170
+ }
5171
+ }
5172
+ @data['image_size'][5] = checkbox('원본 px'){
5173
+ on_toggled{
5174
+ if @data['image_size'][5].checked?
5175
+ @data['image_size'][1].checked = false
5176
+ @data['image_size'][2].checked = false
5177
+ @data['image_size'][3].checked = false
5178
+ @data['image_size'][0].checked = false
5179
+ @data['image_size'][4].checked = false
5072
5180
  end
5073
5181
  }
5074
5182
  }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cafe_buy_duo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.37
4
+ version: 0.1.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-23 00:00:00.000000000 Z
10
+ date: 2025-05-29 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: File to Clipboard gem
13
13
  email: mymin26@naver.com