v0.16.6 Handling for broken input images... again.
This commit is contained in:
parent
a94dfbb550
commit
ae0efcb489
@ -1,5 +1,5 @@
|
||||
# gossamer threads migration-import code
|
||||
# v0.16.5
|
||||
# v0.16.6
|
||||
|
||||
require 'mysql2'
|
||||
require 'open-uri'
|
||||
@ -395,8 +395,9 @@ class GossamerForumsImporter < ImportScripts::Base
|
||||
# Helper method to resize an image to specified dimensions
|
||||
def resize_image(file_path, max_width, max_height)
|
||||
resized_path = file_path.sub(File.extname(file_path), "_resized#{File.extname(file_path)}")
|
||||
begin
|
||||
system("convert #{file_path} -resize #{max_width}x#{max_height} #{resized_path}")
|
||||
resized_path
|
||||
resized_path if File.exist?(resized_path)
|
||||
rescue => e
|
||||
puts "Failed to resize image #{file_path}: #{e.message}"
|
||||
nil
|
||||
@ -457,15 +458,17 @@ class GossamerForumsImporter < ImportScripts::Base
|
||||
end
|
||||
|
||||
# Resize the image for the avatar / profile picture (200x200)
|
||||
begin
|
||||
resized_image_path = resize_image(temp_file.path, 200, 200)
|
||||
if resized_image_path.nil?
|
||||
raise "Image resize failed" if resized_image_path.nil?
|
||||
resized_temp_file = Tempfile.new(['user_image_resized', '.png'])
|
||||
FileUtils.copy_file(resized_image_path, resized_temp_file.path)
|
||||
rescue => e
|
||||
puts "Skipping image due to resize failure: #{temp_file.path}"
|
||||
temp_file.close
|
||||
temp_file.unlink
|
||||
next
|
||||
end
|
||||
resized_temp_file = Tempfile.new(['user_image_resized', '.png'])
|
||||
FileUtils.copy_file(resized_image_path, resized_temp_file.path)
|
||||
|
||||
# Only handle the first image for avator and profile settings
|
||||
if images_imported == 0
|
||||
|
Loading…
Reference in New Issue
Block a user