wp_posting_duo 0.0.11 → 0.0.13

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/wp_posting_duo.rb +72 -245
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06450a5281e0dd2b80e5cbce3d850b5f42286b525dec3f0929476be1356d3e35
4
- data.tar.gz: 212bbd79860449e789f40b6b95fa54f5ee4c3ce99d9b877ba854491ed94c3431
3
+ metadata.gz: 484347fe6285924f3c72ca0d2bcc9ff657e10b74d53d91fa2504f87ed5e88ede
4
+ data.tar.gz: 5969bceea54588cde40d9fffad780d0bca877fc1719f90524b78d02b2e23f1dc
5
5
  SHA512:
6
- metadata.gz: ca9f5c1b8fdeaf8f44457f92331bab29be2c10058deeea5cbc70c0a8b3ea3ab2c43554c5e9aee1e4a7a2fea67e72534f0d39b83617843148edf1aa1c975a5986
7
- data.tar.gz: 56f7d211330c42f1cdd4bc2a3ea921e05abc2827815631572b0fc638e21e046c3879f6ad4da130e29c2fe8497d5eb2796d8e1ee06eeb966ae4c14f18192bf01a
6
+ metadata.gz: 36113eb3895963e4823858e058045cb26a1d0f948f1a4406d890b9aefbc44d585f51f73d9820a161235b583a166d83ed2c94a35999154fbc4373409205bb3db1
7
+ data.tar.gz: 123a95dac0facd827db318f076dc90cdfa5380122b787d1637b7833dfc6332a4d5a2c6074cf5c6a9c8d874639b215f6663c0d25193d6ba679d2732784e4256ee
@@ -512,7 +512,6 @@ class Wordpress
512
512
  end
513
513
  end
514
514
 
515
-
516
515
  def color_image
517
516
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
518
517
  image = Magick::Image.new(740, 740) { |k| k.background_color = color.sample }
@@ -521,188 +520,80 @@ class Wordpress
521
520
 
522
521
  def save_image
523
522
  if @data['이미지설정']['이미지'].length == 0
524
- return
525
- end
526
-
527
- if @data['이미지설정']['순서사용'].checked?
528
- image_path = @data['이미지설정']['이미지'][@image_counter][2]
529
- @image_counter += 1
530
- if @image_counter > @data['이미지설정']['이미지'].length - 1
531
- @image_counter = 0
532
- end
523
+
533
524
  else
534
- # 초기화가 안됐거나 다 썼으면 새롭게 섞는다
535
- @shuffled_images ||= []
536
- if @shuffled_images.empty?
537
- @shuffled_images = @data['이미지설정']['이미지'].shuffle
525
+ if @data['이미지설정']['순서사용'].checked?
526
+ image_path = @data['이미지설정']['이미지'][@image_counter][2]
527
+ @image_counter += 1
528
+ if @image_counter > @data['이미지설정']['이미지'].length-1
529
+ @image_counter = 0
530
+ end
531
+ else
532
+ image_path = @data['이미지설정']['이미지'].sample[2]
538
533
  end
539
-
540
- image_path = @shuffled_images.shift[2]
534
+ img = Magick::Image.read(image_path).first
535
+ img.write('./image/memory.png')
541
536
  end
542
-
543
- img = Magick::Image.read(image_path).first
544
- img.write('./image/memory.png')
545
537
  end
546
538
 
547
539
  def change_image_size(w)
548
540
  img = Magick::Image.read('./image/memory.png').first
549
541
  width = img.columns
550
542
  height = img.rows
551
-
552
- # '원본' 선택된 경우, 리사이징을 하지 않고 원본 이미지를 그대로 반환
553
- if w == 'original'
554
- return img # 원본 이미지 그대로 반환
555
- else
556
- begin
557
- if @data['image_type'][0].checked? or @data['image_type'][2].checked?
558
- # 비율을 맞추어 리사이징
559
- img.resize!(w, w * (height.to_f / width.to_f))
560
- else
561
- # 정사각형으로 리사이징
562
- img.resize!(w, w)
563
- end
564
- rescue
565
- img.resize!(w, w) # 예외 처리 시에도 리사이징
543
+ begin
544
+ if @data['image_type'][0].checked? or @data['image_type'][2].checked?
545
+ img.resize!(w, w*(height.to_f/width.to_f))
546
+ else
547
+ img.resize!(w, w)
566
548
  end
549
+ rescue
550
+ img.resize!(w, w)
567
551
  end
568
-
569
- # 리사이징된 이미지 저장
570
552
  img.write('./image/memory.png')
571
553
  end
572
554
 
573
- def wrap_text_to_fit(draw, text, max_width, max_height, font_path, initial_size)
574
- size = initial_size
575
- draw.font = font_path
576
-
577
- loop do
578
- draw.pointsize = size
579
- words = text.chars # 글자 단위로 자름 (한국어 기준)
580
- lines = []
581
- line = ""
582
-
583
- words.each do |char|
584
- test_line = line + char
585
- metrics = draw.get_type_metrics(test_line)
586
- if metrics.width > max_width
587
- lines << line
588
- line = char
589
- else
590
- line = test_line
591
- end
555
+ def image_text(text1, text2)
556
+ begin
557
+ color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
558
+ font = Dir.entries('./fonts')
559
+ img = Magick::Image.read('./image/memory.png').first
560
+ text = Magick::Draw.new
561
+ color2 = color.sample
562
+ font2 = './fonts/'+font.sample
563
+ message = text1.to_s+"\n"+text2.to_s
564
+ begin
565
+ size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
566
+ rescue
567
+ size = 30
592
568
  end
593
- lines << line unless line.empty?
594
-
595
- line_height = draw.get_type_metrics("가").height
596
- total_height = line_height * lines.size
597
-
598
- # 세로 초과 안 하면 성공
599
- if total_height <= max_height || size <= 10
600
- return [lines.join("\n"), size]
601
- else
602
- size -= 2
569
+ if @data['이미지설정']['글자그림자'].checked?
570
+ img.annotate(text, 0,0, +3,+3, message) do
571
+ text.gravity = Magick::CenterGravity
572
+ text.pointsize = size
573
+ text.fill = '#000000'
574
+ text.font = font2
575
+ end
603
576
  end
604
- end
605
- end
606
-
607
-
608
- def image_text(text1, text2)
609
- begin
610
- color = File.open('./color.ini', 'r', encoding: 'utf-8').read.split("\n").map(&:strip).reject(&:empty?)
611
- font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
612
- font2 = './fonts/' + font_files.sample
613
-
614
- # 랜덤 글자색 선택
615
- color2 = color.sample
616
-
617
- # 헬퍼 함수: 색상 문자열 '#RRGGBB' -> [R,G,B] 배열로 변환
618
- def hex_to_rgb(hex)
619
- hex = hex.delete('#')
620
- [hex[0..1], hex[2..3], hex[4..5]].map { |c| c.to_i(16) }
621
- end
622
-
623
- # 헬퍼 함수: 두 RGB 색상의 차이 계산 (간단한 유클리드 거리)
624
- def color_distance(c1, c2)
625
- Math.sqrt(
626
- (c1[0] - c2[0])**2 +
627
- (c1[1] - c2[1])**2 +
628
- (c1[2] - c2[2])**2
629
- )
630
- end
631
-
632
- # 대비가 충분히 되는 테두리 색상 선택
633
- max_attempts = 10
634
- stroke_color = nil
635
- base_rgb = hex_to_rgb(color2)
636
-
637
- max_attempts.times do
638
- candidate = color.sample
639
- candidate_rgb = hex_to_rgb(candidate)
640
- dist = color_distance(base_rgb, candidate_rgb)
641
-
642
- # 거리(차이) 임계값 100 (0~441 범위) — 필요시 조절 가능
643
- if dist > 100
644
- stroke_color = candidate
645
- break
646
- end
647
- end
648
- stroke_color ||= '#000000' # 만약 충분히 다른 색 없으면 검정색 기본값
649
-
650
- img = Magick::Image.read('./image/memory.png').first
651
- draw = Magick::Draw.new
652
577
 
653
- raw_message = "#{text1}\n#{text2}".strip
654
- max_width = img.columns * 0.85
655
- max_height = img.rows * 0.6
656
-
657
- begin
658
- size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
578
+ img.annotate(text, 0,0,0,0, message) do
579
+ text.gravity = Magick::CenterGravity
580
+ text.pointsize = size
581
+ if @data['이미지설정']['글자테두리'].checked?
582
+ text.stroke_width = 2
583
+ text.stroke = '#000000'
584
+ end
585
+ text.fill = color2
586
+ text.font = font2
587
+ end
588
+
589
+ img.write('./image/memory.png')
659
590
  rescue
660
- size = 30
661
- end
662
-
663
- wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
664
-
665
- if @data['이미지설정']['글자그림자'].checked?
666
- img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
667
- draw.gravity = Magick::CenterGravity
668
- draw.pointsize = adjusted_size
669
- draw.fill = '#000000'
670
- draw.font = font2
671
- end
591
+ puts '이미지 폰트 불러오기 오류 재시도...'
592
+ sleep(3)
593
+ retry
672
594
  end
673
-
674
- if @data['이미지설정']['글자테두리'].checked?
675
- draw_stroke = Magick::Draw.new
676
- img.annotate(draw_stroke, 0, 0, 0, 0, wrapped_message) do
677
- draw_stroke.gravity = Magick::CenterGravity
678
- draw_stroke.pointsize = adjusted_size
679
- draw_stroke.fill = 'none'
680
- draw_stroke.stroke = stroke_color
681
- draw_stroke.stroke_width = rand(5..10)
682
- draw_stroke.font = font2
683
- end
684
- end
685
-
686
- draw2 = Magick::Draw.new
687
- img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
688
- draw2.gravity = Magick::CenterGravity
689
- draw2.pointsize = adjusted_size
690
- draw2.fill = color2
691
- draw2.stroke = 'none'
692
- draw2.font = font2
693
- end
694
-
695
- img.write('./image/memory.png')
696
-
697
- rescue => e
698
- puts "이미지 폰트 불러오기 오류 재시도... (#{e.message})"
699
- sleep(3)
700
- retry
701
- end
702
595
  end
703
596
 
704
-
705
-
706
597
  def border()
707
598
  color = File.open('./color.ini', 'r',:encoding => 'utf-8').read().split("\n")
708
599
  img = Magick::Image.read('./image/memory.png').first
@@ -728,86 +619,48 @@ class Wordpress
728
619
  else
729
620
  auto_image()
730
621
  end
731
-
732
- # '원본'을 포함한 이미지 크기 옵션 추가
733
- image_size = [480, 740, 650, 550, 480, 'original']
622
+
623
+ image_size = [480,740,650,550,480]
734
624
  size = 0
735
-
736
- for n in 0..5 # 0부터 5까지 반복, '원본' 옵션까지 포함
625
+ for n in 0..4
737
626
  if @data['image_size'][n].checked?
738
- if n == 5 # '원본'이 선택되었을 경우
739
- size = 'original'
740
- elsif n == 0
741
- size = image_size.sample # 랜덤 선택
627
+ if n == 0
628
+ size = image_size.sample
742
629
  else
743
630
  size = image_size[n]
744
631
  end
745
632
  end
746
633
  end
747
-
748
- # '원본'이 선택되지 않았다면 기본 값 설정
749
634
  if size == 0
750
635
  size = 480
751
636
  end
752
-
753
- change_image_size(size) # 크기 변경 함수 호출
754
637
 
638
+ change_image_size(size)
755
639
 
756
640
  if @data['이미지설정']['필터사용'].checked?
757
641
  image_filter()
758
642
  end
759
643
 
644
+ insert_image_text1 = ''
645
+ insert_image_text2 = ''
760
646
  if @data['이미지설정']['글자삽입1'].checked?
761
- if @data['이미지설정']['이미지글자1'].length == 0
762
- image_text_path1 = ''
763
- else
764
- if @data['이미지설정']['글자랜덤'].checked?
765
- image_text_path1 = @data['이미지설정']['이미지글자1'].sample
766
- else
767
- image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
768
- @image_text_soon1 += 1
769
- if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
770
- @image_text_soon1 = 0
771
- end
772
- end
773
- end
647
+ insert_image_text1 = @data['이미지설정']['이미지글자1'].sample
774
648
  end
775
649
 
776
650
  if @data['이미지설정']['글자삽입2'].checked?
777
- if @data['이미지설정']['이미지글자2'].length == 0
778
- image_text_path2 = ''
779
- else
780
- if @data['이미지설정']['글자랜덤'].checked?
781
- image_text_path2 = @data['이미지설정']['이미지글자2'].sample
782
- else
783
- image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
784
- @image_text_soon2 += 1
785
- if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
786
- @image_text_soon2 = 0
787
- end
788
- end
789
- end
651
+ insert_image_text2 = @data['이미지설정']['이미지글자2'].sample
790
652
  end
791
-
653
+
792
654
  if @data['이미지설정']['글자삽입1'].checked? or @data['이미지설정']['글자삽입2'].checked?
793
- image_text(image_text_path1, image_text_path2)
655
+ image_text(insert_image_text1, insert_image_text2)
794
656
  end
795
657
 
796
658
  if @data['이미지설정']['테두리사용'].checked?
797
659
  border()
798
660
  end
799
661
 
800
- sleep(1)
801
662
  time = Time.now.to_s.split(' ')[0..1].join('').split(':').join('').split('-').join('')
802
663
  FileUtils.cp('./image/memory.png', './image/'+@keyword+time+'.png')
803
- hi_dir = Dir.pwd
804
- iconv = Iconv.new('UTF-8', 'CP949')
805
- begin
806
- hi_dir = iconv.iconv(hi_dir)
807
- rescue
808
-
809
- end
810
- return hi_dir+'/image/'+@keyword+time+'.png'
811
664
  end
812
665
 
813
666
  def image_update22
@@ -2506,27 +2359,17 @@ class Wordpress
2506
2359
  }
2507
2360
  button('폴더째로불러오기'){
2508
2361
  stretchy false
2509
- on_clicked {
2362
+ on_clicked{
2510
2363
  path = @data['이미지설정']['폴더경로'].text.to_s.force_encoding('utf-8')
2364
+ Dir.entries(@data['이미지설정']['폴더경로'].text.to_s).each do |file|
2365
+ if file == '.' or file == '..'
2511
2366
 
2512
- # 경로가 유효한지 확인
2513
- if Dir.exist?(path)
2514
- Dir.entries(path).each do |file|
2515
- if file == '.' or file == '..'
2516
- next
2517
- else
2518
- # 폴더 내의 파일을 이미지 리스트에 추가
2519
- @data['이미지설정']['이미지'] << [false, file, path + "\\" + file.force_encoding('utf-8')]
2520
- end
2367
+ else
2368
+ @data['이미지설정']['이미지'] << [false, file, path+"\\"+file.force_encoding('utf-8')]
2521
2369
  end
2522
-
2523
- # 마지막 빈 항목 추가 후 제거 (원래 로직에 맞춰)
2524
- @data['이미지설정']['이미지'] << []
2525
- @data['이미지설정']['이미지'].pop
2526
- else
2527
- # 경로가 존재하지 않으면 경고 메시지 출력
2528
- puts "경로가 존재하지 않습니다: #{path}"
2529
2370
  end
2371
+ @data['이미지설정']['이미지'] << []
2372
+ @data['이미지설정']['이미지'].pop
2530
2373
  }
2531
2374
  }
2532
2375
  }
@@ -2674,7 +2517,6 @@ class Wordpress
2674
2517
  @data['image_size'][2].checked = false
2675
2518
  @data['image_size'][3].checked = false
2676
2519
  @data['image_size'][4].checked = false
2677
- @data['image_size'][5].checked = false
2678
2520
  end
2679
2521
  }
2680
2522
  }
@@ -2685,7 +2527,6 @@ class Wordpress
2685
2527
  @data['image_size'][2].checked = false
2686
2528
  @data['image_size'][3].checked = false
2687
2529
  @data['image_size'][4].checked = false
2688
- @data['image_size'][5].checked = false
2689
2530
  end
2690
2531
  }
2691
2532
  }
@@ -2696,7 +2537,6 @@ class Wordpress
2696
2537
  @data['image_size'][0].checked = false
2697
2538
  @data['image_size'][3].checked = false
2698
2539
  @data['image_size'][4].checked = false
2699
- @data['image_size'][5].checked = false
2700
2540
  end
2701
2541
  }
2702
2542
  }
@@ -2707,7 +2547,6 @@ class Wordpress
2707
2547
  @data['image_size'][2].checked = false
2708
2548
  @data['image_size'][0].checked = false
2709
2549
  @data['image_size'][4].checked = false
2710
- @data['image_size'][5].checked = false
2711
2550
  end
2712
2551
  }
2713
2552
  }
@@ -2718,18 +2557,6 @@ class Wordpress
2718
2557
  @data['image_size'][2].checked = false
2719
2558
  @data['image_size'][3].checked = false
2720
2559
  @data['image_size'][0].checked = false
2721
- @data['image_size'][5].checked = false
2722
- end
2723
- }
2724
- }
2725
- @data['image_size'][5] = checkbox('원본 px'){
2726
- on_toggled{
2727
- if @data['image_size'][5].checked?
2728
- @data['image_size'][1].checked = false
2729
- @data['image_size'][2].checked = false
2730
- @data['image_size'][3].checked = false
2731
- @data['image_size'][0].checked = false
2732
- @data['image_size'][4].checked = false
2733
2560
  end
2734
2561
  }
2735
2562
  }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wp_posting_duo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - zon
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-06-26 00:00:00.000000000 Z
10
+ date: 2025-07-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: File to Clipboard gem
13
13
  email: mymin26@naver.com