wp_posting_zon 0.0.10 → 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_zon.rb +91 -260
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f04627d200e810ce3c8d7a486338588d2a250af9637a6518e9fc138b920ef044
4
- data.tar.gz: 07c3abc9d388f1fa21cb2a44de1e7abd96b7a64b7bb4c95367b1a6b938f042d2
3
+ metadata.gz: f5f66606e7c15dd39601538be977010587b0d0724918f1adebfbe8469e3a12df
4
+ data.tar.gz: df6c76b2edd6f7f96081fa8ce546dcc6e8bbeaf2c27ad749f80e4b4ccd130b1a
5
5
  SHA512:
6
- metadata.gz: 1ac9e938a5db2569f5b017031ce81ef7431f8908c0b657abf9cee6d9f1922836e77a63038ef26a07492b12acf6c6c7a1ff51e31ecf2108c313c6a9d16aa872bc
7
- data.tar.gz: 77a94363459c89ee91ae980405118f96267aad62d9c872269b093212545c2d551b07caad7323f1f849a46199136716278a97c25a6495b178a3da39fbbdf0ed70
6
+ metadata.gz: 7d8d433bf91223f1393b2165594c3f4412d5c3712f01f03034fe855b0fc958f529a6c1911167d2aed49cc030a3cea4cdd8b32470749abc17ad3e80ab49b6647e
7
+ data.tar.gz: 1a21a9337fea50aaf4ae93ff3ae92a2f5a822e4c049406789b860a2f6eb2ed2f2a225011da3cb54ba729db87186edfb5e8bc7abe04a956848b2da902ac3da6bd
@@ -339,24 +339,28 @@ class Wordpress
339
339
  end
340
340
 
341
341
  def crop_image_height_under_width(path, min_crop_ratio = 0.625)
342
- img = Magick::Image.read(path).first
343
- width = img.columns
344
- height = img.rows
345
-
346
-
342
+ img = Magick::Image.read(path).first
343
+ width = img.columns
344
+ height = img.rows
347
345
 
348
- if height > width
349
- min_height = (width * min_crop_ratio).to_i
350
- new_height = rand(min_height..width)
351
- crop_top = ((height - new_height) / 2.0).round
346
+ if height > width
347
+ min_height = (width * min_crop_ratio).to_i
348
+ new_height = rand(min_height..width)
349
+ crop_top = ((height - new_height) / 2.0).round
352
350
 
353
- cropped = img.crop(0, crop_top, width, new_height, true)
354
- cropped.write(path)
351
+ cropped = img.crop(0, crop_top, width, new_height, true)
355
352
 
356
-
357
- else
358
-
359
- end
353
+ retries = 0
354
+ begin
355
+ cropped.write(path)
356
+ rescue => e
357
+ retries += 1
358
+ puts "이미지 저장 오류 (#{e.message}), 재시도 #{retries}/5"
359
+ sleep(1)
360
+ retry if retries < 5
361
+ raise "이미지 저장 실패: #{e.message}"
362
+ end
363
+ end
360
364
  end
361
365
 
362
366
  def auto_image(keyword = nil)
@@ -443,7 +447,6 @@ class Wordpress
443
447
  end
444
448
  end
445
449
 
446
-
447
450
  def color_image
448
451
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
449
452
  image = Magick::Image.new(740, 740) { |k| k.background_color = color.sample }
@@ -452,188 +455,80 @@ class Wordpress
452
455
 
453
456
  def save_image
454
457
  if @data['이미지설정']['이미지'].length == 0
455
- return
456
- end
457
-
458
- if @data['이미지설정']['순서사용'].checked?
459
- image_path = @data['이미지설정']['이미지'][@image_counter][2]
460
- @image_counter += 1
461
- if @image_counter > @data['이미지설정']['이미지'].length - 1
462
- @image_counter = 0
463
- end
458
+
464
459
  else
465
- # 초기화가 안됐거나 다 썼으면 새롭게 섞는다
466
- @shuffled_images ||= []
467
- if @shuffled_images.empty?
468
- @shuffled_images = @data['이미지설정']['이미지'].shuffle
460
+ if @data['이미지설정']['순서사용'].checked?
461
+ image_path = @data['이미지설정']['이미지'][@image_counter][2]
462
+ @image_counter += 1
463
+ if @image_counter > @data['이미지설정']['이미지'].length-1
464
+ @image_counter = 0
465
+ end
466
+ else
467
+ image_path = @data['이미지설정']['이미지'].sample[2]
469
468
  end
470
-
471
- image_path = @shuffled_images.shift[2]
469
+ img = Magick::Image.read(image_path).first
470
+ img.write('./image/memory.png')
472
471
  end
473
-
474
- img = Magick::Image.read(image_path).first
475
- img.write('./image/memory.png')
476
472
  end
477
473
 
478
474
  def change_image_size(w)
479
475
  img = Magick::Image.read('./image/memory.png').first
480
476
  width = img.columns
481
477
  height = img.rows
482
-
483
- # '원본' 선택된 경우, 리사이징을 하지 않고 원본 이미지를 그대로 반환
484
- if w == 'original'
485
- return img # 원본 이미지 그대로 반환
486
- else
487
- begin
488
- if @data['image_type'][0].checked? or @data['image_type'][2].checked?
489
- # 비율을 맞추어 리사이징
490
- img.resize!(w, w * (height.to_f / width.to_f))
491
- else
492
- # 정사각형으로 리사이징
493
- img.resize!(w, w)
494
- end
495
- rescue
496
- img.resize!(w, w) # 예외 처리 시에도 리사이징
478
+ begin
479
+ if @data['image_type'][0].checked? or @data['image_type'][2].checked?
480
+ img.resize!(w, w*(height.to_f/width.to_f))
481
+ else
482
+ img.resize!(w, w)
497
483
  end
484
+ rescue
485
+ img.resize!(w, w)
498
486
  end
499
-
500
- # 리사이징된 이미지 저장
501
487
  img.write('./image/memory.png')
502
488
  end
503
489
 
504
- def wrap_text_to_fit(draw, text, max_width, max_height, font_path, initial_size)
505
- size = initial_size
506
- draw.font = font_path
507
-
508
- loop do
509
- draw.pointsize = size
510
- words = text.chars # 글자 단위로 자름 (한국어 기준)
511
- lines = []
512
- line = ""
513
-
514
- words.each do |char|
515
- test_line = line + char
516
- metrics = draw.get_type_metrics(test_line)
517
- if metrics.width > max_width
518
- lines << line
519
- line = char
520
- else
521
- line = test_line
522
- end
490
+ def image_text(text1, text2)
491
+ begin
492
+ color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
493
+ font = Dir.entries('./fonts')
494
+ img = Magick::Image.read('./image/memory.png').first
495
+ text = Magick::Draw.new
496
+ color2 = color.sample
497
+ font2 = './fonts/'+font.sample
498
+ message = text1.to_s+"\n"+text2.to_s
499
+ begin
500
+ size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
501
+ rescue
502
+ size = 30
523
503
  end
524
- lines << line unless line.empty?
525
-
526
- line_height = draw.get_type_metrics("가").height
527
- total_height = line_height * lines.size
528
-
529
- # 세로 초과 안 하면 성공
530
- if total_height <= max_height || size <= 10
531
- return [lines.join("\n"), size]
532
- else
533
- size -= 2
504
+ if @data['이미지설정']['글자그림자'].checked?
505
+ img.annotate(text, 0,0, +3,+3, message) do
506
+ text.gravity = Magick::CenterGravity
507
+ text.pointsize = size
508
+ text.fill = '#000000'
509
+ text.font = font2
510
+ end
534
511
  end
535
- end
536
- end
537
-
538
-
539
- def image_text(text1, text2)
540
- begin
541
- color = File.open('./color.ini', 'r', encoding: 'utf-8').read.split("\n").map(&:strip).reject(&:empty?)
542
- font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
543
- font2 = './fonts/' + font_files.sample
544
-
545
- # 랜덤 글자색 선택
546
- color2 = color.sample
547
-
548
- # 헬퍼 함수: 색상 문자열 '#RRGGBB' -> [R,G,B] 배열로 변환
549
- def hex_to_rgb(hex)
550
- hex = hex.delete('#')
551
- [hex[0..1], hex[2..3], hex[4..5]].map { |c| c.to_i(16) }
552
- end
553
-
554
- # 헬퍼 함수: 두 RGB 색상의 차이 계산 (간단한 유클리드 거리)
555
- def color_distance(c1, c2)
556
- Math.sqrt(
557
- (c1[0] - c2[0])**2 +
558
- (c1[1] - c2[1])**2 +
559
- (c1[2] - c2[2])**2
560
- )
561
- end
562
-
563
- # 대비가 충분히 되는 테두리 색상 선택
564
- max_attempts = 10
565
- stroke_color = nil
566
- base_rgb = hex_to_rgb(color2)
567
-
568
- max_attempts.times do
569
- candidate = color.sample
570
- candidate_rgb = hex_to_rgb(candidate)
571
- dist = color_distance(base_rgb, candidate_rgb)
572
-
573
- # 거리(차이) 임계값 100 (0~441 범위) — 필요시 조절 가능
574
- if dist > 100
575
- stroke_color = candidate
576
- break
577
- end
578
- end
579
- stroke_color ||= '#000000' # 만약 충분히 다른 색 없으면 검정색 기본값
580
-
581
- img = Magick::Image.read('./image/memory.png').first
582
- draw = Magick::Draw.new
583
-
584
- raw_message = "#{text1}\n#{text2}".strip
585
- max_width = img.columns * 0.85
586
- max_height = img.rows * 0.6
587
512
 
588
- begin
589
- size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
513
+ img.annotate(text, 0,0,0,0, message) do
514
+ text.gravity = Magick::CenterGravity
515
+ text.pointsize = size
516
+ if @data['이미지설정']['글자테두리'].checked?
517
+ text.stroke_width = 2
518
+ text.stroke = '#000000'
519
+ end
520
+ text.fill = color2
521
+ text.font = font2
522
+ end
523
+
524
+ img.write('./image/memory.png')
590
525
  rescue
591
- size = 30
592
- end
593
-
594
- wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
595
-
596
- if @data['이미지설정']['글자그림자'].checked?
597
- img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
598
- draw.gravity = Magick::CenterGravity
599
- draw.pointsize = adjusted_size
600
- draw.fill = '#000000'
601
- draw.font = font2
602
- end
603
- end
604
-
605
- if @data['이미지설정']['글자테두리'].checked?
606
- draw_stroke = Magick::Draw.new
607
- img.annotate(draw_stroke, 0, 0, 0, 0, wrapped_message) do
608
- draw_stroke.gravity = Magick::CenterGravity
609
- draw_stroke.pointsize = adjusted_size
610
- draw_stroke.fill = 'none'
611
- draw_stroke.stroke = stroke_color
612
- draw_stroke.stroke_width = rand(5..10)
613
- draw_stroke.font = font2
614
- end
526
+ puts '이미지 폰트 불러오기 오류 재시도...'
527
+ sleep(3)
528
+ retry
615
529
  end
616
-
617
- draw2 = Magick::Draw.new
618
- img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
619
- draw2.gravity = Magick::CenterGravity
620
- draw2.pointsize = adjusted_size
621
- draw2.fill = color2
622
- draw2.stroke = 'none'
623
- draw2.font = font2
624
- end
625
-
626
- img.write('./image/memory.png')
627
-
628
- rescue => e
629
- puts "이미지 폰트 불러오기 오류 재시도... (#{e.message})"
630
- sleep(3)
631
- retry
632
- end
633
530
  end
634
531
 
635
-
636
-
637
532
  def border()
638
533
  color = File.open('./color.ini', 'r',:encoding => 'utf-8').read().split("\n")
639
534
  img = Magick::Image.read('./image/memory.png').first
@@ -659,86 +554,48 @@ class Wordpress
659
554
  else
660
555
  auto_image()
661
556
  end
662
-
663
- # '원본'을 포함한 이미지 크기 옵션 추가
664
- image_size = [480, 740, 650, 550, 480, 'original']
557
+
558
+ image_size = [480,740,650,550,480]
665
559
  size = 0
666
-
667
- for n in 0..5 # 0부터 5까지 반복, '원본' 옵션까지 포함
560
+ for n in 0..4
668
561
  if @data['image_size'][n].checked?
669
- if n == 5 # '원본'이 선택되었을 경우
670
- size = 'original'
671
- elsif n == 0
672
- size = image_size.sample # 랜덤 선택
562
+ if n == 0
563
+ size = image_size.sample
673
564
  else
674
565
  size = image_size[n]
675
566
  end
676
567
  end
677
568
  end
678
-
679
- # '원본'이 선택되지 않았다면 기본 값 설정
680
569
  if size == 0
681
570
  size = 480
682
571
  end
683
-
684
- change_image_size(size) # 크기 변경 함수 호출
685
572
 
573
+ change_image_size(size)
686
574
 
687
575
  if @data['이미지설정']['필터사용'].checked?
688
576
  image_filter()
689
577
  end
690
578
 
579
+ insert_image_text1 = ''
580
+ insert_image_text2 = ''
691
581
  if @data['이미지설정']['글자삽입1'].checked?
692
- if @data['이미지설정']['이미지글자1'].length == 0
693
- image_text_path1 = ''
694
- else
695
- if @data['이미지설정']['글자랜덤'].checked?
696
- image_text_path1 = @data['이미지설정']['이미지글자1'].sample
697
- else
698
- image_text_path1 = @data['이미지설정']['이미지글자1'][@image_text_soon1]
699
- @image_text_soon1 += 1
700
- if @image_text_soon1 > @data['이미지설정']['이미지글자1'].length - 1
701
- @image_text_soon1 = 0
702
- end
703
- end
704
- end
582
+ insert_image_text1 = @data['이미지설정']['이미지글자1'].sample
705
583
  end
706
584
 
707
585
  if @data['이미지설정']['글자삽입2'].checked?
708
- if @data['이미지설정']['이미지글자2'].length == 0
709
- image_text_path2 = ''
710
- else
711
- if @data['이미지설정']['글자랜덤'].checked?
712
- image_text_path2 = @data['이미지설정']['이미지글자2'].sample
713
- else
714
- image_text_path2 = @data['이미지설정']['이미지글자2'][@image_text_soon2]
715
- @image_text_soon2 += 1
716
- if @image_text_soon2 > @data['이미지설정']['이미지글자2'].length - 1
717
- @image_text_soon2 = 0
718
- end
719
- end
720
- end
586
+ insert_image_text2 = @data['이미지설정']['이미지글자2'].sample
721
587
  end
722
-
588
+
723
589
  if @data['이미지설정']['글자삽입1'].checked? or @data['이미지설정']['글자삽입2'].checked?
724
- image_text(image_text_path1, image_text_path2)
590
+ image_text(insert_image_text1, insert_image_text2)
725
591
  end
726
592
 
727
593
  if @data['이미지설정']['테두리사용'].checked?
728
594
  border()
729
595
  end
730
596
 
731
- sleep(1)
732
597
  time = Time.now.to_s.split(' ')[0..1].join('').split(':').join('').split('-').join('')
733
598
  FileUtils.cp('./image/memory.png', './image/'+@keyword+time+'.png')
734
- hi_dir = Dir.pwd
735
- iconv = Iconv.new('UTF-8', 'CP949')
736
- begin
737
- hi_dir = iconv.iconv(hi_dir)
738
- rescue
739
-
740
- end
741
- return hi_dir+'/image/'+@keyword+time+'.png'
742
599
  end
743
600
 
744
601
  def image_update22
@@ -2431,27 +2288,17 @@ class Wordpress
2431
2288
  }
2432
2289
  button('폴더째로불러오기'){
2433
2290
  stretchy false
2434
- on_clicked {
2291
+ on_clicked{
2435
2292
  path = @data['이미지설정']['폴더경로'].text.to_s.force_encoding('utf-8')
2293
+ Dir.entries(@data['이미지설정']['폴더경로'].text.to_s).each do |file|
2294
+ if file == '.' or file == '..'
2436
2295
 
2437
- # 경로가 유효한지 확인
2438
- if Dir.exist?(path)
2439
- Dir.entries(path).each do |file|
2440
- if file == '.' or file == '..'
2441
- next
2442
- else
2443
- # 폴더 내의 파일을 이미지 리스트에 추가
2444
- @data['이미지설정']['이미지'] << [false, file, path + "\\" + file.force_encoding('utf-8')]
2445
- end
2296
+ else
2297
+ @data['이미지설정']['이미지'] << [false, file, path+"\\"+file.force_encoding('utf-8')]
2446
2298
  end
2447
-
2448
- # 마지막 빈 항목 추가 후 제거 (원래 로직에 맞춰)
2449
- @data['이미지설정']['이미지'] << []
2450
- @data['이미지설정']['이미지'].pop
2451
- else
2452
- # 경로가 존재하지 않으면 경고 메시지 출력
2453
- puts "경로가 존재하지 않습니다: #{path}"
2454
2299
  end
2300
+ @data['이미지설정']['이미지'] << []
2301
+ @data['이미지설정']['이미지'].pop
2455
2302
  }
2456
2303
  }
2457
2304
  }
@@ -2599,7 +2446,6 @@ class Wordpress
2599
2446
  @data['image_size'][2].checked = false
2600
2447
  @data['image_size'][3].checked = false
2601
2448
  @data['image_size'][4].checked = false
2602
- @data['image_size'][5].checked = false
2603
2449
  end
2604
2450
  }
2605
2451
  }
@@ -2610,7 +2456,6 @@ class Wordpress
2610
2456
  @data['image_size'][2].checked = false
2611
2457
  @data['image_size'][3].checked = false
2612
2458
  @data['image_size'][4].checked = false
2613
- @data['image_size'][5].checked = false
2614
2459
  end
2615
2460
  }
2616
2461
  }
@@ -2621,7 +2466,6 @@ class Wordpress
2621
2466
  @data['image_size'][0].checked = false
2622
2467
  @data['image_size'][3].checked = false
2623
2468
  @data['image_size'][4].checked = false
2624
- @data['image_size'][5].checked = false
2625
2469
  end
2626
2470
  }
2627
2471
  }
@@ -2632,7 +2476,6 @@ class Wordpress
2632
2476
  @data['image_size'][2].checked = false
2633
2477
  @data['image_size'][0].checked = false
2634
2478
  @data['image_size'][4].checked = false
2635
- @data['image_size'][5].checked = false
2636
2479
  end
2637
2480
  }
2638
2481
  }
@@ -2643,18 +2486,6 @@ class Wordpress
2643
2486
  @data['image_size'][2].checked = false
2644
2487
  @data['image_size'][3].checked = false
2645
2488
  @data['image_size'][0].checked = false
2646
- @data['image_size'][5].checked = false
2647
- end
2648
- }
2649
- }
2650
- @data['image_size'][5] = checkbox('원본 px'){
2651
- on_toggled{
2652
- if @data['image_size'][5].checked?
2653
- @data['image_size'][1].checked = false
2654
- @data['image_size'][2].checked = false
2655
- @data['image_size'][3].checked = false
2656
- @data['image_size'][0].checked = false
2657
- @data['image_size'][4].checked = false
2658
2489
  end
2659
2490
  }
2660
2491
  }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wp_posting_zon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
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