@@ -118,30 +118,38 @@ func writeUserError(error util.MessageError) error {
118
118
return util .WriteJsonToStdOut (MisConfigurationError {Message : error .Error (), Code : error .ErrorCode ()})
119
119
}
120
120
121
- func validateImageSize (file string , recommendedMinSize int ) error {
121
+ func validateImageSize (file string , recommendedMinSize int ) ( int , error ) {
122
122
firstFileBytes , err := fs .ReadFile (file , 512 )
123
123
if err != nil {
124
- return errors .WithStack (err )
124
+ return 0 , errors .WithStack (err )
125
125
}
126
126
127
127
if IsIco (firstFileBytes ) {
128
128
for _ , size := range GetIcoSizes (firstFileBytes ) {
129
129
if size .Width >= recommendedMinSize && size .Height >= recommendedMinSize {
130
- return nil
130
+ if size .Width > size .Height {
131
+ return size .Width , nil
132
+ } else {
133
+ return size .Height , nil
134
+ }
131
135
}
132
136
}
133
137
} else {
134
138
config , err := DecodeImageConfig (file )
135
139
if err != nil {
136
- return errors .WithStack (err )
140
+ return 0 , errors .WithStack (err )
137
141
}
138
142
139
143
if config .Width >= recommendedMinSize && config .Height >= recommendedMinSize {
140
- return nil
144
+ if config .Width > config .Height {
145
+ return config .Width , nil
146
+ } else {
147
+ return config .Height , nil
148
+ }
141
149
}
142
150
}
143
151
144
- return NewImageSizeError (file , recommendedMinSize )
152
+ return 0 , NewImageSizeError (file , recommendedMinSize )
145
153
}
146
154
147
155
func outputFormatToSingleFileExtension (outputFormat string ) string {
@@ -177,14 +185,14 @@ func doConvertIcon(sourceFiles []string, roots []string, outputFormat string, ou
177
185
isOutputFormatIco := outputFormat == "ico"
178
186
if strings .HasSuffix (resolvedPath , outExt ) {
179
187
if outputFormat != "icns" {
180
- err = validateImageSize (resolvedPath , inputInfo .recommendedMinSize )
188
+ inputInfo . MaxIconSize , err = validateImageSize (resolvedPath , inputInfo .recommendedMinSize )
181
189
if err != nil {
182
190
return nil , errors .WithStack (err )
183
191
}
184
192
}
185
193
186
194
// size not required in this case
187
- return []IconInfo {{File : resolvedPath }}, nil
195
+ return []IconInfo {{File : resolvedPath , Size : inputInfo . MaxIconSize }}, nil
188
196
}
189
197
190
198
if fileInfo .IsDir () {
@@ -287,7 +295,7 @@ func convertSingleFile(inputInfo *InputFileInfo, outFile string, outputFormat st
287
295
if err != nil {
288
296
return nil , errors .WithStack (err )
289
297
}
290
- return []IconInfo {{File : outFile }}, err
298
+ return []IconInfo {{File : outFile , Size : inputInfo . MaxIconSize }}, err
291
299
292
300
case "ico" :
293
301
maxImage , err := inputInfo .GetMaxImage ()
@@ -299,7 +307,7 @@ func convertSingleFile(inputInfo *InputFileInfo, outFile string, outputFormat st
299
307
if err != nil {
300
308
return nil , errors .WithStack (err )
301
309
}
302
- return []IconInfo {{File : outFile }}, nil
310
+ return []IconInfo {{File : outFile , Size : inputInfo . MaxIconSize }}, nil
303
311
304
312
default :
305
313
return nil , errors .Errorf ("unknown output format %s" , outputFormat )
0 commit comments