Skip to content

Commit

Permalink
Implement embedding picture title into image file
Browse files Browse the repository at this point in the history
The --embed-meta parameter will create a copy of the image
with picture title embedded on top right corner of the file.
The title size is adjusted to the current screen scaling factor.
The image is also resized to match the screen resolution to make
sure the title text will not get resized or cropped by Windows.
  • Loading branch information
ORelio committed Sep 7, 2019
1 parent 682eee0 commit 0cceac8
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 16 deletions.
5 changes: 4 additions & 1 deletion README-En.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=====================================================
==== SpotlightDL v1.3 - By ORelio - Microzoom.fr ====
==== SpotlightDL v1.4 - By ORelio - Microzoom.fr ====
=====================================================

Thanks for dowloading SpotlightDL!
Expand Down Expand Up @@ -118,6 +118,9 @@ R: Default mode downloads a list of images returned by a single API call: previo
Q: Some images do not have a title or copyright in their metadata?
R: Those fields are not provided for all images by the Spotlight API.

Q: I do not want to have the image title inside my wallpaper or lockscreen. How to remove it?
R: Edit the batch file you want to use and remove --embed-meta inside the corresponding command.

+--------------------+
| © 2018-2019 ORelio |
+--------------------+
5 changes: 4 additions & 1 deletion README-Fr.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
======================================================
==== SpotlightDL v1.3 - Par ORelio - Microzoom.fr ====
==== SpotlightDL v1.4 - Par ORelio - Microzoom.fr ====
======================================================

Merci d'avoir téléchargé SpotlightDL!
Expand Down Expand Up @@ -120,6 +120,9 @@ R: Par défaut, la liste d'images retournées par un seul appel API: précédemm
Q: Certaines images n'ont pas de titre ou de copyright dans leur métadonnées?
R: Ces informations ne sont pas fournies pour toutes les images au niveau de l'API Windows à la une.

Q: Je ne veux pas du titre de l'image sur mon fond d'écran ou écran de verrouillage. Comment l'enlever ?
R: Modifiez le fichier batch que vous utilisez pour enlever le paramètre --embed-meta dans la commande associée.

+--------------------+
| © 2018-2019 ORelio |
+--------------------+
2 changes: 1 addition & 1 deletion Scripts/update-archive-and-lockscreen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ if not "%errorlevel%" == "0" (

mkdir SpotlightArchive > nul 2>&1
SpotlightDownloader download --maxres --metadata --outdir SpotlightArchive
SpotlightDownloader lockscreen --from-dir SpotlightArchive
SpotlightDownloader lockscreen --from-dir SpotlightArchive --embed-meta --outname lockscreen
2 changes: 1 addition & 1 deletion Scripts/update-archive-and-wallpaper.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ cd "%~dp0"

mkdir SpotlightArchive > nul 2>&1
SpotlightDownloader download --maxres --metadata --outdir SpotlightArchive
SpotlightDownloader wallpaper --from-dir SpotlightArchive
SpotlightDownloader wallpaper --from-dir SpotlightArchive --embed-meta --outname wallpaper
2 changes: 1 addition & 1 deletion Scripts/update-lockscreen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ if not "%errorlevel%" == "0" (

mkdir SpotlightCache > nul 2>&1
SpotlightDownloader download --amount 10 --cache-size 10 --metadata --outdir SpotlightCache
SpotlightDownloader lockscreen --from-dir SpotlightCache
SpotlightDownloader lockscreen --from-dir SpotlightCache --embed-meta --outname lockscreen
2 changes: 1 addition & 1 deletion Scripts/update-wallpaper.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ cd "%~dp0"

mkdir SpotlightCache > nul 2>&1
SpotlightDownloader download --amount 10 --cache-size 10 --metadata --outdir SpotlightCache
SpotlightDownloader wallpaper --from-dir SpotlightCache
SpotlightDownloader wallpaper --from-dir SpotlightCache --embed-meta --outname wallpaper
20 changes: 20 additions & 0 deletions SpotlightDownloader/Desktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,25 @@ public static void RefreshDesktop()
System.Diagnostics.Process.Start("RUNDLL32.EXE", "USER32.DLL,UpdatePerUserSystemParameters 1, True");
UpdatePerUserSystemParameters();
}

//stackoverflow.com/questions/5977445/

[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
enum DeviceCap
{
VERTRES = 10,
DESKTOPVERTRES = 117,
}

public static float GetScalingFactor()
{
System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);
float ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;
return ScreenScalingFactor; // 1.25 = 125%
}
}
}
2 changes: 1 addition & 1 deletion SpotlightDownloader/Lockscreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void RestoreDefaultGlobalLockscreen()
Win7_RegistryKey(false);
}
}
else if ((WindowsVersion.WinMajorVersion == 6 && WindowsVersion.WinMajorVersion >= 2) /* Windows 8 and 10 */
else if ((WindowsVersion.WinMajorVersion == 6 && WindowsVersion.WinMinorVersion >= 2) /* Windows 8 and 10 */
|| WindowsVersion.WinMajorVersion >= 10 /* Windows 10 and future Windows versions - might not work on newer versions */)
{
string lockscreenDir = Win10_InitDir();
Expand Down
23 changes: 15 additions & 8 deletions SpotlightDownloader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
namespace SpotlightDownloader
{
/// <summary>
/// Download Microsoft Spotlight images - By ORelio (c) 2018 - CDDL 1.0
/// Download Microsoft Spotlight images - By ORelio (c) 2018-2019 - CDDL 1.0
/// </summary>
class Program
{
public const string Name = "SpotlightDL";
public const string Version = "1.3";
public const string Version = "1.4";

static void Main(string[] args)
{
Expand All @@ -30,6 +30,7 @@ static void Main(string[] args)
int downloadAmount = int.MaxValue;
int cacheSize = int.MaxValue;
bool metadata = false;
bool embedMetadata = false;
string fromFile = null;
int apiTryCount = 3;

Expand Down Expand Up @@ -149,6 +150,9 @@ static void Main(string[] args)
case "--metadata":
metadata = true;
break;
case "--embed-meta":
embedMetadata = true;
break;
case "--from-file":
i++;
if (i < args.Length)
Expand Down Expand Up @@ -272,13 +276,15 @@ static void Main(string[] args)
{
if (singleImage || action == "wallpaper" || action == "lockscreen")
{
string outputFile = fromFile ?? randomImage.DownloadToFile(outputDir, integrityCheck, metadata, outputName, apiTryCount);
Console.WriteLine(outputFile);
string imageFile = fromFile ?? randomImage.DownloadToFile(outputDir, integrityCheck, metadata, outputName, apiTryCount);
if (embedMetadata)
imageFile = SpotlightImage.EmbedMetadata(imageFile, outputDir, outputName);
Console.WriteLine(imageFile);
if (action == "wallpaper")
{
try
{
Desktop.SetWallpaper(fromFile ?? outputFile);
Desktop.SetWallpaper(imageFile);
}
catch (Exception e)
{
Expand All @@ -292,7 +298,7 @@ static void Main(string[] args)
{
try
{
Lockscreen.SetGlobalLockscreen(fromFile ?? outputFile);
Lockscreen.SetGlobalLockscreen(imageFile);
}
catch (Exception e)
{
Expand Down Expand Up @@ -352,7 +358,7 @@ static void Main(string[] args)
.OrderByDescending(fileInfo => fileInfo.CreationTime)
.Skip(cacheSize))
{
string metadataFile = Path.Combine(imgToDelete.DirectoryName, Path.GetFileNameWithoutExtension(imgToDelete.Name) + ".txt");
string metadataFile = SpotlightImage.GetMetaLocation(imgToDelete.FullName);
if (File.Exists(metadataFile))
File.Delete(metadataFile);
imgToDelete.Delete();
Expand Down Expand Up @@ -393,10 +399,11 @@ static void Main(string[] args)
" --portrait Force portrait image instead of autodetecting from current screen res",
" --landscape Force landscape image instead of autodetecting from current screen res",
" --outdir <dir> Set output directory instead of defaulting to working directory",
" --outname <name> Set output file name as <name>.jpg in single image mode, ignored otherwise",
" --outname <name> Set output file name as <name>.ext for --single or --embed-meta",
" --skip-integrity Skip integrity check of downloaded files: file size and sha256 hash",
" --api-tries <n> Amount of unsuccessful API calls before giving up. Default is 3.",
" --metadata Also save image metadata such as title & copyright as <image-name>.txt",
" --embed-meta When available, embed metadata into wallpaper or locksceeen image",
" --from-file Set the specified file as wallpaper/lockscreen instead of downloading",
" --from-dir Set a random image from the specified directory as wallpaper/lockscreen",
" --restore Restore the default lockscreen image, has no effect with other actions",
Expand Down
4 changes: 4 additions & 0 deletions SpotlightDownloader/SpotlightDownloader.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<StartArguments>
</StartArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<StartArguments>
</StartArguments>
</PropertyGroup>
</Project>
Loading

0 comments on commit 0cceac8

Please sign in to comment.