element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog A Raspberry Pi2 random pisture display
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 26 May 2016 3:35 PM Date Created
  • Views 809 views
  • Likes 1 like
  • Comments 4 comments
  • raspberry_pi_projects
Related
Recommended

A Raspberry Pi2 random pisture display

Former Member
Former Member
26 May 2016

I wanted to use my new Pi2 as a "random picture display", but I didn't want to install the "media center"
I was very frustrated with using python and the pygame "resources" (whatever they call it)
Ultimately, I decided to try a different approach; html with javascript!

Here's the html/javascript solution, which works perfectly!

copy everything below!  and have fun!!

 

 

// this is a "random picture display" javascript
// you open it with your browser and the browser does all the work
// well, aside from your having to put the image informtion in
// I will the datadable on my windows machine, using a visual basic program that i wrote
// hope this works for you as well as it does for me!

// I'm running it on a Raspberyy Pi 2, with the standard installation (not the media install)
// the display is set to portrait orientation on the Pi in the config file
// by using sudo nano boot/config.txt
// adding the line
// display_rotate=3
// which results in a clock wise 270 degree screen rotation

// if you added instead
// display_rotate=1
// it would result in a clock wise90 degree screen rotation

 

<form id="newwindow" name="newwindow">
</form>
<>
<html>
<head>

<title>Awesome Images</title>
<meta http-equiv="Content-Type"  content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#000000" text="#000000">

</body>

<table width="100%" height="97%" border="0">

<tr>

<td>
<p align="center" valign="center">
<img name="SlideC">

</td>
</tr>

</table>

 

 

</html>

 

 

<script language="JavaScript1.2" >

var newimg;
var wid;
var hit;
var currentdate = 0;
var theranlink = " ";
var core = 0;
var created = 0;
var imgstrt = 0;
var imgstp = 0;
var imgcnt = 0;
var imgary = 0;
var chk = 0;
var hrat = 0;
var wrat = 0;
var intvl=15000;

// maxwid is the width of your Pi's display in pixels
// maxhit is the heigth of your Pi's display in pixels
// this is set up for a monitor rotated to a Portrait orientation
var maxwid=728;
var maxhit=1266;
// if you wanted a landscape orientation you would comment the two line above (use leading //)
// and uncomment the two lines below
//var maxwid=1266;
//var maxhit=728;

 

// picpath points to the "root directory" of your images
// this way you can copy this file to your desktop once filled with the picture array
var picpath="/media/pi/Transcend/pics/";

 

 

g_iimg = 0;
g_imax = 0;
g_ImageTable = new Array();

var time = new Date().getTime();

function ChangeImage(fFwd)
{
g_iimg=Math.floor((Math.random()*g_imax));
Update();
}

function Update()
{
mag=1;

//centimg=picpath + g_ImageTable[g_iimg][0];

centimg=g_ImageTable[g_iimg][0];
newWindow2(centimg);
}

function Next()
{
mag=1;
ChangeImage(true);
}

function main()
{
if(new Date().getTime() - time >= intvl){

ChangeImage();
}else{
      
}
}

 

 

function newWindow2(newimg)
{
wid=g_ImageTable[g_iimg][1];
hit=g_ImageTable[g_iimg][2];
wwid=(wid);
whit=(hit);
wrat=wwid/maxwid;
hrat=whit/maxhit;

chk=0;
if (hrat>1){
chk=1}
if (wrat>1){
chk=1}

irat=hrat/wrat;
if (chk=1){
if (hrat>wrat) {

SlideC.src=newimg;
SlideC.width=wwid/hrat;
slideC.height=whit/hrat;

} else {

SlideC.src=newimg;
SlideC.width=wwid/wrat;
slideC.height=whit/wrat;

}

}
}

// ********************************************************** insert data table here ***********************************************************************************
// the data table must follow this format, and the quotation marks must remain
// g_ImageTable[g_imax++] = new Array ("imge name","image width in pixels","image heigth in pixels");
// an example of the array where it is used directly iin the directoy is below
// g_ImageTable[g_imax++] = new Array ("flower.jpg","768","1024");

// if you have multiple directories under the root that you want it to access then the array is this format
// g_ImageTable[g_imax++] = new Array ("directory name/image name","image width in pixels","image heigth in pixels");
// an example of the array where it is used from a root directoy is below
// g_ImageTable[g_imax++] = new Array ("garden_pictures/flower.jpg","768","1024");

 

 

 

//******************************************** end of data table *************************************btw, it is unlimited in the number of images you can insert bove

 

 

 

 

// dely makes a 0 to 20 second pause
dely=Math.floor((Math.random()*20000));

// the variable dely above is added to a "standard delay" of 20 seconds
// this yields a variable refresh time of 20 to 40 seconds
intvl=20000+dely;

 

//do not add anything below this line
setInterval(main, intvl);

Next();

mag=1;
g_iimg=Math.floor((Math.random()*g_imax));

</script>

  • Sign in to reply

Top Comments

  • DAB
    DAB over 9 years ago +2
    You had me worried until I realized that you meant Picture, not Pisture. DAB
  • Former Member
    Former Member over 9 years ago in reply to DAB

    If you try it, please let me know if it worked for you!  This was built using an earlier javascript that I wrote that needed image size info because there were zoom in and out buttons.  You might be able to just put in "1",s for the image dimensions (not "0"'s 'cause it might make a calculation error in the script)...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 9 years ago

    You had me worried until I realized that you meant Picture, not Pisture.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    oh, and noticed I had not commented on in the original post, in function update...
    the script has this code

     

    function Update()
    {
    mag=1;

    //centimg=picpath + g_ImageTable[g_iimg][0];

    centimg=g_ImageTable[g_iimg][0];
    newWindow2(centimg);
    }

     

    the comment I should have added ---
    the current script is set to run in the directory with the files...

    //centimg=picpath + g_ImageTable[g_iimg][0];

    centimg=g_ImageTable[g_iimg][0];

     

    If it is running from your desktop etc, you should change those two lines to this

    centimg=picpath + g_ImageTable[g_iimg][0];

    //centimg=g_ImageTable[g_iimg][0];

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    and, since I got it working nicely, I had to go buy a bigger display!  It is capable of 1920x1080 resolution, so I've changed maxwid and maxhit (on my copy of this script) to 1040 and 1820 respectively.

     

    Showing random images this way takes little computing power from the Pi (peaks at about 20%) and only when the image is first being displayed, then the processor demand drops to 0%.  I am using a 4Gb flash drive plugged directly into the Pi, and have 1000's of images on it.  The Pi is powered by the monitor's USB port, and I'm using wireless networking and a wireless keyboard/mouse pad combo.

     

    The neat part, to me anyway, is that I'm still using the Rasbian system, and I have "full use" of the P!i

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube