Skip to content

Commit

Permalink
Add option for resizing image to below skylab limit
Browse files Browse the repository at this point in the history
  • Loading branch information
kev-le committed Sep 24, 2024
1 parent f963a15 commit 283129f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ using SkylabStudio;
var apiClient = new StudioClient("YOUR_SKYLAB_API_TOKEN");
// option to configure max concurrent downloads (for when using DownloadAllPhotos method)
// defaults to 5 concurrent downloads at a time
var studioOptions = new StudioOptions { MaxConcurrentDownloads = 5 };
// optional: to configure max concurrent downloads (for when using DownloadAllPhotos method)
// - defaults to 5 concurrent downloads at a time
// optional: to resize oversized images to be below Skylab dimension limit
// - defaults to false
var studioOptions = new StudioOptions { MaxConcurrentDownloads = 5, ResizeImageIfOversized = true };
var apiClient = new StudioClient(Environment.GetEnvironmentVariable("SKYLAB_API_TOKEN"), studioOptions);
```

Expand Down
29 changes: 23 additions & 6 deletions StudioClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,49 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudioClient", "StudioClient\StudioClient.csproj", "{0F41D41D-9264-4E44-8313-4F959BC82C31}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StudioClient", "StudioClient\StudioClient.csproj", "{0F41D41D-9264-4E44-8313-4F959BC82C31}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudioClient.Example", "StudioClient.Example\StudioClient.Example.csproj", "{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StudioClient.Example", "StudioClient.Example\StudioClient.Example.csproj", "{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudioClient.Tests", "StudioClient.Tests\StudioClient.Tests.csproj", "{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StudioClient.Tests", "StudioClient.Tests\StudioClient.Tests.csproj", "{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0F41D41D-9264-4E44-8313-4F959BC82C31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F41D41D-9264-4E44-8313-4F959BC82C31}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F41D41D-9264-4E44-8313-4F959BC82C31}.Debug|x64.ActiveCfg = Debug|Any CPU
{0F41D41D-9264-4E44-8313-4F959BC82C31}.Debug|x64.Build.0 = Debug|Any CPU
{0F41D41D-9264-4E44-8313-4F959BC82C31}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F41D41D-9264-4E44-8313-4F959BC82C31}.Release|Any CPU.Build.0 = Release|Any CPU
{0F41D41D-9264-4E44-8313-4F959BC82C31}.Release|x64.ActiveCfg = Release|Any CPU
{0F41D41D-9264-4E44-8313-4F959BC82C31}.Release|x64.Build.0 = Release|Any CPU
{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}.Debug|x64.ActiveCfg = Debug|x64
{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}.Debug|x64.Build.0 = Debug|x64
{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}.Release|Any CPU.Build.0 = Release|Any CPU
{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}.Release|x64.ActiveCfg = Release|x64
{1D0ACA01-210A-42F3-BC79-B772BF55D9C0}.Release|x64.Build.0 = Release|x64
{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}.Debug|x64.ActiveCfg = Debug|Any CPU
{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}.Debug|x64.Build.0 = Debug|Any CPU
{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}.Release|Any CPU.Build.0 = Release|Any CPU
{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}.Release|x64.ActiveCfg = Release|Any CPU
{5AB68DEF-291E-4A80-9B64-69DAFC3EA10B}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CE6262B9-9C94-4708-9C5F-2044818CEED3}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion StudioClient/Photo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private Dimensions CalculateFinalSize(int? width, int? height, int? orientation)

private Image ResizeImage(Image image, PhotoMetadata metadata)
{
if (metadata == null || !metadata.Bytes.HasValue || !metadata.Width.HasValue || !metadata.Height.HasValue)
if (_resizeImageIfOversized != true || metadata == null || !metadata.Bytes.HasValue || !metadata.Width.HasValue || !metadata.Height.HasValue)
{
return image;
}
Expand Down
3 changes: 3 additions & 0 deletions StudioClient/StudioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ namespace SkylabStudio {
public class StudioOptions
{
public int? MaxConcurrentDownloads { get; set; }
public bool? ResizeImageIfOversized { get; set; }
}

public partial class StudioClient
{
private readonly RestClient _httpClient;
private readonly string _apiKey;
private readonly int _maxConcurrentDownloads = 5;
private readonly bool _resizeImageIfOversized = false;

/// <summary>
/// Initializes a new instance of the <see cref="StudioClient"/> class with the specified API key and options.
Expand All @@ -29,6 +31,7 @@ public StudioClient(string? apiKey = null, StudioOptions? options = null)
_httpClient = new RestClient(baseUrl);
_apiKey = apiKey;
_maxConcurrentDownloads = options?.MaxConcurrentDownloads ?? 5;
_resizeImageIfOversized = options?.ResizeImageIfOversized ?? false;
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions StudioClient/StudioClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="System.Drawing.Common" Version="4.0.2" />
</ItemGroup>

</Project>

0 comments on commit 283129f

Please sign in to comment.