File tree Expand file tree Collapse file tree 3 files changed +100
-0
lines changed
src/Magick.NET/Formats/Icon
tests/Magick.NET.Tests/Formats/Icon/IconWriteDefinesTests Expand file tree Collapse file tree 3 files changed +100
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+ // Licensed under the Apache License, Version 2.0.
3+
4+ using System . Collections . Generic ;
5+
6+ namespace ImageMagick . Formats ;
7+
8+ /// <summary>
9+ /// Class for defines that are used when a <see cref="MagickFormat.Jp2"/> image is written.
10+ /// </summary>
11+ public sealed class IconWriteDefines : IWriteDefines
12+ {
13+ /// <summary>
14+ /// Gets or sets a value indicating whether automatic resizing is enabled.
15+ /// </summary>
16+ public bool ? AutoResize { get ; set ; }
17+
18+ /// <summary>
19+ /// Gets the format where the defines are for.
20+ /// </summary>
21+ public MagickFormat Format
22+ => MagickFormat . Icon ;
23+
24+ /// <summary>
25+ /// Gets the defines that should be set as a define on an image.
26+ /// </summary>
27+ public IEnumerable < IDefine > Defines
28+ {
29+ get
30+ {
31+ if ( AutoResize . HasValue )
32+ yield return new MagickDefine ( Format , "auto-resize" , AutoResize . Value ) ;
33+ }
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ // Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+ // Licensed under the Apache License, Version 2.0.
3+
4+ using ImageMagick ;
5+ using ImageMagick . Formats ;
6+ using Xunit ;
7+
8+ namespace Magick . NET . Tests ;
9+
10+ public partial class IconWriteDefinesTests
11+ {
12+ public class TheAutoResizeProperty
13+ {
14+ [ Fact ]
15+ public void ShouldSetTheDefine ( )
16+ {
17+ var defines = new IconWriteDefines
18+ {
19+ AutoResize = true ,
20+ } ;
21+
22+ using var image = new MagickImage ( ) ;
23+ image . Settings . SetDefines ( defines ) ;
24+
25+ Assert . Equal ( "true" , image . Settings . GetDefine ( MagickFormat . Icon , "auto-resize" ) ) ;
26+ }
27+
28+ [ Fact ]
29+ public void ShouldEncodeTheImageIn8bitWhenNotSet ( )
30+ {
31+ var defines = new IconWriteDefines
32+ {
33+ AutoResize = false ,
34+ } ;
35+
36+ using var image = new MagickImage ( ) ;
37+ image . Settings . SetDefines ( defines ) ;
38+
39+ Assert . Equal ( "false" , image . Settings . GetDefine ( MagickFormat . Icon , "auto-resize" ) ) ;
40+ }
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ // Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+ // Licensed under the Apache License, Version 2.0.
3+
4+ using ImageMagick ;
5+ using ImageMagick . Formats ;
6+ using Xunit ;
7+
8+ namespace Magick . NET . Tests ;
9+
10+ public partial class IconWriteDefinesTests
11+ {
12+ public class TheConstructor
13+ {
14+ [ Fact ]
15+ public void ShouldNotSetAnyDefines ( )
16+ {
17+ using var image = new MagickImage ( ) ;
18+ image . Settings . SetDefines ( new IconWriteDefines ( ) ) ;
19+
20+ Assert . Null ( image . Settings . GetDefine ( MagickFormat . Icon , "auto-resize" ) ) ;
21+ }
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments