chore: update dependencies in Dockerfile and Gemfile

- Remove unused `ruby-vips` gem from Gemfile
- Update Dockerfile to remove `libvips42` package, which is no longer needed
- Comment out legacy watermarking code in `AddWatermarkToWeatherArtWorker`

These changes streamline the dependencies, making the
project lighter and reduce potential security issues with
unused gems and packages. The watermarking functionality is now
commented out for potential future use but is not currently
needed.
This commit is contained in:
songtianlun 2025-02-05 14:53:54 +08:00
parent 1790b2d50c
commit cd26313808
4 changed files with 24 additions and 25 deletions

View File

@ -16,7 +16,7 @@ WORKDIR /rails
# Install base packages
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 libpq5 redis-tools libvips42 && \
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 libpq5 redis-tools && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Set production environment

View File

@ -61,7 +61,7 @@ gem "sidekiq", "~> 7.3"
gem "sidekiq-scheduler", "~> 5.0"
gem "image_processing", "~> 1.13"
gem "ruby-vips", "~> 2.2"
# gem "ruby-vips", "~> 2.2"
gem "mini_magick", "~> 4.13.2"
group :development, :test do

View File

@ -534,7 +534,6 @@ DEPENDENCIES
rails (~> 8.0.1)
rubocop-rails-omakase
ruby-openai (~> 7.3)
ruby-vips (~> 2.2)
selenium-webdriver
sidekiq (~> 7.3)
sidekiq-scheduler (~> 5.0)

View File

@ -18,33 +18,33 @@ class AddWatermarkToWeatherArtWorker
def add_watermark
return if weather_art.image_with_watermark.attached?
watermark_path = Rails.root.join("app/assets/images/today_ai_weather_copyright_watermark1.png")
return unless File.exist?(watermark_path)
# watermark_path = Rails.root.join("app/assets/images/today_ai_weather_copyright_watermark1.png")
# return unless File.exist?(watermark_path)
image_tempfile = nil
watermark_tempfile = nil
begin
image_tempfile = weather_art.image.download
return unless image_dimensions_are_sufficient?(image_tempfile.path)
# image_tempfile = nil
# watermark_tempfile = nil
# begin
# image_tempfile = weather_art.image.download
# return unless image_dimensions_are_sufficient?(image_tempfile.path)
image = ImageProcessing::Vips.source(image_tempfile.path)
watermark = ImageProcessing::Vips.source(watermark_path)
watermarked_image = image.composite(watermark, "overlay")
watermark_tempfile = Tempfile.new([ "watermarked_image", ".png" ])
watermarked_image.write_to_file(watermark_tempfile.path)
weather_art.image_with_watermark.attach(
io: File.open(watermark_tempfile.path),
filename: "#{generate_filename("watermarked")}",
content_type: "image/png"
)
ensure
watermark_tempfile.unlink if watermark_tempfile
end
# image = ImageProcessing::Vips.source(image_tempfile.path)
# watermark = ImageProcessing::Vips.source(watermark_path)
# watermarked_image = image.composite(watermark, "overlay")
# watermark_tempfile = Tempfile.new([ "watermarked_image", ".png" ])
# watermarked_image.write_to_file(watermark_tempfile.path)
# weather_art.image_with_watermark.attach(
# io: File.open(watermark_tempfile.path),
# filename: "#{generate_filename("watermarked")}",
# content_type: "image/png"
# )
# ensure
# watermark_tempfile.unlink if watermark_tempfile
# end
end
def image_dimensions_are_sufficient?(image_path)
dimensions = ImageProcessing::Vips.source(image_path).sizes
dimensions.width >= 200 && dimensions.height >= 200
# dimensions = ImageProcessing::Vips.source(image_path).sizes
# dimensions.width >= 200 && dimensions.height >= 200
end
def generate_filename(prefix)