VB icon

Save Lock Windows Images

Email
Submitted on: 8/22/2018 4:59:56 AM
By: David Leatherman 
Level: Advanced
User Rating: Unrated
Compatibility: PHP 3.0, PHP 4.0, PHP 5.0
Views: 619
 
     Partly this is an exercise to demonstrate the versatility of PHP... There ARE other ways to accomplish the same thing... However, that being said... If you like the Windows 10 Lock Window Imagaes and would like to put some or all of them into a gallery (eg. your Background Slideshow, this procedure may be of interest to you. The Lock Window Images are temporarily stored in a deeply 'hidden' folder and periodically changed so that if you do want to save them it is necessary to run this script at least as often as you notice them change.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Save Lock Windows Images
// Description:Partly this is an exercise to demonstrate the versatility of PHP...
	There ARE other ways to accomplish the same thing...
	
		However, that being said...
		
	If you like the Windows 10 Lock Window Imagaes and would like to put some or all of them into
	a gallery (eg. your Background Slideshow, this procedure may be of interest to you.
	The Lock Window Images are temporarily stored in a deeply 'hidden' folder and periodically changed
	so that if you do want to save them it is necessary to run this script at least as often as you notice them change.
// By: David Leatherman
//**************************************

<?php
/*
	Partly this is an exercise to demonstrate the versatility of PHP...
	There ARE other ways to accomplish the same thing...
	
		However, that being said...
		
	If you like the Windows 10 Lock Window Imagaes and would like to put some or all of them into
	a gallery (eg. your Background Slideshow, this procedure may be of interest to you.
	The Lock Window Images are temporarily stored in a deeply 'hidden' folder and periodically changed
	so that if you do want to save them it is necessary to run this script at least as often as you notice them change.
	
	These files all have 64 random character names with no file extension and not all of them are valid jpeg files.
	
	1 - Copy everything in the 'hidden' folder to your working folder, renaming them with a sequentially assigned name and a .jpg extension
		This will make the valid files identifiable (as you will see, later in the process)
		
	2 - Create an array of these file names to distinguish them from the jpeg files you already have in your working directory,
	
	3 - For every file name in that array
		a.	Remove (unlink) files whose file size is less than 150 bytes (smaller are of no interest, IMO).
		b.	Verify that it is a genuine jpeg file (looking for EXIF information), removing files that are not.
		c.	Get the Image Dimensions (height and width)
		d.	Here I excluded portrait and square images (that gives me landscape images to better fit my screen).
		e.	Files that are accepted, are listed, just to inform you what you will be looking for (see below).
		
	4	Execute a shell command to open a viewing window to the working directory in order to examine the accepted files.
	
	5.	You can then sort the files to bring the new files to the top of the list to pick those you do or don't want to keep.
	
	6.	Rename the new files to something more interesting - you could extract exif descriptions for renaming ideas.
		There may be duplicates, as time goes on, because Microsoft will randomly put the same images back in the 'hidden' folder.
		I compare file sizes of the files in the wworking directory to eliminate these cases.
*/
$private = "\your_folder";					// Distinguishing filepath unique to your computer - change to your computer name
$winpath = "C:\Users" . $private . "\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets";
$wrkpath = "D:\DATA\Lock_Window_Images";	// Where you want to keep your gallery of images
$number = 1000;
$dirlist = array();
if ($handle = opendir($winpath)) 
	{
 while (false !== ($entry = readdir($handle))) 
		{
if (($entry != ".") and ($entry != ".."))
			{
			$srce = "$winpath\\$entry";
			$dest = "$wrkpath\\$number.jpg" ;
			copy($srce, $dest);
			$dirlist[] = $dest;
			$number++;
			}
		}
 closedir($handle);
	}
$dcount = count($dirlist);
for ($n=0; $n<$dcount; $n++)
	{
	$name = $dirlist[$n];
	$fsize = filesize($name) / 1024 + .5;
	if ($fsize < 150)
		{
		unlink($name);
		continue;
		}
	
	if (exif_imagetype($name) != IMAGETYPE_JPEG)
		{
		unlink($name);
		continue;
		}
		
	$img = ImageCreateFromJpeg($name);
	$width = imagesx($img);
	$height = imagesy($img);
	if ($width <= $height)
		{
		unlink($name);
		continue;
		}
			
	echo "[" .number_format($fsize,0). "] [" .$width. " x " .$height. "]" .$name. "<br>";
	}
$output = shell_exec('start ' . $wrkpath);
?>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.