@@ -48,10 +48,12 @@ def convert_to_webp(asset_file)
4848 asset_file . get_object ( response_target : f )
4949 end
5050
51+ thumbnail_size = thumbnail_size_for ( input_path )
52+
5153 _stdout , stderr , status = Open3 . capture3 (
5254 { 'VIPS_BLOCK_UNTRUSTED' => '1' } ,
5355 'vipsthumbnail' , input_path . to_s ,
54- '-s' , '800' ,
56+ '-s' , thumbnail_size ,
5557 '-o' , output_path . to_s + '[Q=72,preset=drawing,smart_subsample=true,effort=6,strip=true]'
5658 )
5759 raise "vipsthumbnail failed (status=#{ status . exitstatus } ): #{ stderr } " unless status . success?
@@ -61,6 +63,23 @@ def convert_to_webp(asset_file)
6163 content
6264 end
6365
66+ THUMBNAIL_MAX_SIZE = 800
67+
68+ # Avoid enlarging images smaller than THUMBNAIL_MAX_SIZE
69+ def thumbnail_size_for ( input_path )
70+ stdout , _ , status = Open3 . capture3 (
71+ { 'VIPS_BLOCK_UNTRUSTED' => '1' } ,
72+ 'vipsheader' , '-f' , 'width' , input_path . to_s
73+ )
74+ if status . success?
75+ input_width = stdout . strip . to_i
76+ if input_width > 0 && input_width < THUMBNAIL_MAX_SIZE
77+ return input_width . to_s
78+ end
79+ end
80+ THUMBNAIL_MAX_SIZE . to_s
81+ end
82+
6483 def push_to_github ( gi , repo , asset_file , webp_content )
6584 octokit = gi . octokit
6685 images_path = @conference . github_repo_images_path . chomp ( '/' )
0 commit comments