Wednesday, August 20, 2014

Raspberry Pi Picture Frame Post 12 Image Resizing

As I said in my last update I said that I wanted to resize images to save space on the pi. To do this I am going to use imagemagick. You can install it using the code below.
sudo apt-get update
sudo apt-get install imagemagick
If I remember correctly I mentioned earlier that capitalization is extremely important with Linux. This includes file extensions. If you use my scripts the slide show will only show .JPG files not .jpg. So to fix that we need to make sure all of the pictures have .JPG as there extension. This is done with one simple line of code.
rename 's/\.jpg$/\.JPG/' *.jpg
Now if you want an explanation of what everything in the code means go here. I tried to explain it but in the end that's where I got the help from and that website does a much better job. So I gave up on explaining. Now all of our files have the same .JPG extension. Next we will resize the pictures. If you want to just do one the command is convert input.JPG-resize 1280x1024 output.JPG. Now in that case we can change the file name output and the extension. However when we do a batch process it does not work nicely. Below is the batch convert code. 
for file in *.JPG; do convert $file -resize 1280x1024\> $file; done;
Now lets break that down. for file in *.JPG; What this means is for each file found with the .JPG extension we will do the following. The $file allows the command to use the file name from the for section. The done at the end says that we are done looping commands, go to next file. Just search batch convert imagemagick if you want more information. The \> says to only re size bigger images. This way we don't reprocess each image every night. Now I am going to add this to the grive.sh script. What I want it to do is check for changes (aka new pictures) and download if there are, then convert the files, then sync the new files to the web. 

No comments:

Post a Comment