diff --git a/README b/README index e094725..f910e78 100644 --- a/README +++ b/README @@ -42,3 +42,11 @@ metaflac --dont-use-padding file.flac + +--- imagemagick --- +https://imagemagick.org/script/download.php +For Image Resizing +magick + Cover + -resize 750x750 + Cover_small.jpg diff --git a/TODO b/TODO index 8d58706..7debbcb 100644 --- a/TODO +++ b/TODO @@ -1,2 +1 @@ -Add Cover Resize via lib or command ??? Implement main diff --git a/main.cpp b/main.cpp index 444c7ef..72d694f 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,7 @@ constexpr bool IS_FLAC = false; constexpr bool IS_JPG = true; constexpr bool IS_PNG = false; constexpr uint32_t COVER_SIZE = 750; +constexpr const char MAGICK_INVOKE[] = "magick"; #ifdef _WIN32 constexpr const char FOLDER_DELIM = '\\'; @@ -349,13 +350,20 @@ string get_track_filename(int track_num, const string& artist, return filename; } -bool should_resize_JPG(ifstream& file) +bool should_resize_JPG(const string& path) { // Do a resize by default bool result = true; + ifstream file; + string filename; int marker = 0; int symbol; + filename = path; + filename += FOLDER_DELIM; + filename += "Cover"; + file.open(filename); + // Check Header 1 symbol = file.get(); if (symbol != 0xFF) @@ -476,17 +484,21 @@ bool should_resize_JPG(ifstream& file) } } -bool should_resize_PNG(ifstream& file) +bool should_resize_PNG(const string& path) { + ifstream file; + string filename; uint8_t buf[4]; uint32_t width; uint32_t height; + filename = path; + filename += FOLDER_DELIM; + filename += "Cover"; + file.open(filename); + // Seek - file.read(reinterpret_cast(&buf), 4); - file.read(reinterpret_cast(&buf), 4); - file.read(reinterpret_cast(&buf), 4); - file.read(reinterpret_cast(&buf), 4); + file.seekg(16); // Read width width = 0; @@ -506,6 +518,8 @@ bool should_resize_PNG(ifstream& file) height += buf[i]; } + file.close(); + if ((width > COVER_SIZE) || (height > COVER_SIZE)) { return true; @@ -543,6 +557,45 @@ bool get_cover_type(const string& path) throw invalid_argument(filename); } +bool resize_cover(const string& path, bool is_jpg) +{ + string cmd; + bool should_resize; + + // Should we actually resize + if (is_jpg == IS_JPG) + { + should_resize = should_resize_JPG(path); + } + else + { + should_resize = should_resize_PNG(path); + } + + cmd = MAGICK_INVOKE; + cmd += "\""; + cmd += path; + cmd += FOLDER_DELIM; + cmd += "Cover"; + cmd += "\" "; + + if (should_resize) + { + cmd += "-resize "; + cmd += to_string(COVER_SIZE); + cmd += "x"; + cmd += to_string(COVER_SIZE); + cmd += " "; + } + + cmd += "\""; + cmd += path; + cmd += FOLDER_DELIM; + cmd += "Cover_small.jpg\""; + + return system_command(cmd); +} + bool rename_cover(const string& path, bool is_jpg) { string filename; @@ -751,7 +804,12 @@ bool full_donwload(const string& path, const string& release_prefix, return false; } - // TODO: Make 750x750 Cover JPEG Image + // Make 750x750 Cover JPEG Image + ok = resize_cover(release_dir, cover_is_jpg); + if (!ok) + { + return false; + } // Rename Cover Image (Proper Extension) ok = rename_cover(release_dir, cover_is_jpg);