Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate thumbnails for albums on startup #11

Merged
merged 1 commit into from Sep 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Models/AlbumCollection.cs
Expand Up @@ -10,11 +10,13 @@ public class AlbumCollection
{
private IHostingEnvironment _environment;
private static readonly string[] _extensions = { ".jpg", ".jpeg", ".gif", ".png" };
private readonly ImageProcessor _imageProcessor;

public AlbumCollection(IHostingEnvironment environment)
public AlbumCollection(IHostingEnvironment environment, ImageProcessor imageProcessor)
{
_environment = environment;
Albums = new List<Album>();
_imageProcessor = imageProcessor;

Initialize(environment.WebRootPath);
}
Expand Down Expand Up @@ -61,7 +63,23 @@ private Album GetAlbum(string albumPath)
album.Photos.AddRange(photos);
album.Sort();

GenerateThumbnails(album);

return album;
}

private void GenerateThumbnails(Album album)
{
foreach (var photo in album.Photos)
{
if (String.IsNullOrWhiteSpace(photo.GetThumbnailLink((int)ImageType.Thumbnail, out _)))
{
using (var imageStream = File.OpenRead(photo.AbsolutePath))
{
_imageProcessor.CreateThumbnails(imageStream, photo.AbsolutePath);
}
}
}
}
}
}