CD/DVD/Blu-ray cover

 Certainly! Here's a simple Ruby program that creates basic CD/DVD/Blu-ray cover images for cases. It uses the RMagick gem (a Ruby binding for ImageMagick) to generate and customize images. The program will generate a cover with customizable text and size for different case types.


First, ensure you have ImageMagick installed on your system, and install the RMagick gem:


```bash

gem install rmagick

```


Here's the Ruby script:


```ruby

require 'rmagick'


include Magick


# Define case types and their dimensions (width x height in pixels)

CASE_SIZES = {

  'CD' => [600, 600],

  'DVD' => [900, 1200],

  'Blu-ray' => [1200, 1200]

}


# Function to create a cover

def create_cover(case_type, title, subtitle = "")

  unless CASE_SIZES.key?(case_type)

    puts "Unknown case type. Please choose from: #{CASE_SIZES.keys.join(', ')}"

    return

  end


  width, height = CASE_SIZES[case_type]


  # Create a blank image with white background

  img = Image.new(width, height) { self.background_color = 'white' }


  draw = Draw.new


  # Draw a border

  draw.stroke('black')

  draw.stroke_width(10)

  draw.fill_opacity(0)

  draw.rectangle(0, 0, width - 1, height - 1)

  draw.draw(img)


  # Add Title Text

  title_font_size = (height * 0.1).to_i

  subtitle_font_size = (height * 0.05).to_i


  # Draw Title

  draw = Draw.new

  draw.font = 'Helvetica'

  draw.pointsize = title_font_size

  draw.fill = 'black'

  draw.align = CenterAlign


  # Position for title (centered at top third)

  title_x = width / 2

  title_y = height / 3


  draw.annotate(img, 0, 0, title_x, title_y, title) {

    self.gravity = NorthGravity

  }


  # Draw Subtitle if provided

  unless subtitle.empty?

    draw = Draw.new

    draw.font = 'Helvetica'

    draw.pointsize = subtitle_font_size

    draw.fill = 'gray'

    draw.align = CenterAlign


    # Position for subtitle (centered below title)

    subtitle_x = width / 2

    subtitle_y = height / 2


    draw.annotate(img, 0, 0, subtitle_x, subtitle_y, subtitle) {

      self.gravity = NorthGravity

    }

  end


  # Save the image

  filename = "#{case_type}_cover.png"

  img.write(filename)

  puts "Cover created: #{filename}"

end


# Example usage:

# create_cover('DVD', 'My Awesome Movie', 'Director: Jane Doe')


# Uncomment below lines to test

create_cover('CD', 'Greatest Hits', 'Artist: The Beatles')

create_cover('DVD', 'Epic Movie', 'Director: John Smith')

create_cover('Blu-ray', 'Ultimate Collection', 'Various Artists')

```


### How it works:

- You specify the case type (`CD`, `DVD`, or `Blu-ray`).

- You provide a title and an optional subtitle.

- The script generates a simple cover with borders, centered text, and saves it as a PNG image.


### Customization:

- Change fonts, colors, or add images by modifying the code.

- Adjust sizes and positions as needed for your design preferences.


Let me know if you'd like more advanced features!

Comments

Popular posts from this blog

British Nationals This is A Prison Planet

Cd covers