Welcome to TalkGraphics.com
Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1
    Join Date
    Jun 2017
    Posts
    4

    Default I need a widget that will display a random photo each time pages is loaded.

    Anybody know how to do this in Xara ? Put a photo in a box on a page. Each time the user lands on the page a different photo is displayed in that spot. Even a reload/refresh page triggers it. On Display. It can be either a random pick or one in a specific sequence. I've found places on the internet that show how to code this, but I don't know php or whether php will work with Xara.

  2. #2
    Join Date
    Aug 2000
    Location
    Placitas, New Mexico, USA
    Posts
    41,503

    Default Re: I need a widget that will display a random photo each time pages is loaded.

    I think this can be done with a script. Check back and see if one of our members can suggest one.

  3. #3

    Default Re: I need a widget that will display a random photo each time pages is loaded.

    Hi,

    you could find a widget, but I would do it as follows:-

    Create a php file called random.php in your root folder (where index.htm is), here is the code for it:-
    <?php
    // RANDOM IMAGE SERVER by Sculptex
    // www.sculptex.co.uk
    // Demo @ random.prevoo.uk

    $path = "random/";
    $files = array_diff(scandir($path), array('..', '.'));
    $imgs = array();
    $i = 0;
    foreach($files as $file) {
    $imgs[]= $file;
    $i++;
    }
    $img = $imgs[rand(0,$i-1)];

    $file_extension = strtolower(substr(strrchr($img,"."),1));
    switch( $file_extension ) {
    case "gif": $ctype="image/gif"; break;
    case "png": $ctype="image/png"; break;
    case "jpeg":
    case "jpg": $ctype="image/jpeg"; break;
    default:
    }
    header("Content-type: " . $ctype);
    header("Expires: ". date("r",time() + (1)));
    readfile($path.$img);
    ?>
    Create a folder called random
    Fill folder with required images
    Create placeholder on your website and insert
    <img src='random.php'>
    You can see it in action at http://random.prevoo.uk
    Last edited by sculptex; 15 July 2017 at 07:39 AM. Reason: fixed url

  4. #4
    Join Date
    Feb 2014
    Location
    Toronto, Canada
    Posts
    792

    Default Re: I need a widget that will display a random photo each time pages is loaded.

    That is neat Sculptex, thank you for sharing.

    Ciao

    Roly

  5. #5
    Join Date
    Jun 2017
    Posts
    4

    Default Re: I need a widget that will display a random photo each time pages is loaded.

    I see on the example web site that every image must be the same size and aspect ratio. Is it possible to vary these in size and aspect ratio?

  6. #6
    Join Date
    Aug 2000
    Location
    Harwich, Essex, England
    Posts
    21,917

    Default Re: I need a widget that will display a random photo each time pages is loaded.

    I followed your instruction to the letter Sculptex but I can only get a missing image icon.
    Egg

    Intel i7 - 4790K Quad Core + 16 GB Ram + NVIDIA Geforce GTX 1660 Graphics Card + MSI Optix Mag321 Curv monitor
    + Samsung 970 EVO Plus 500GB SSD + 232 GB SSD + 250 GB SSD portable drive + ISP = BT + Web Hosting = TSO Host

  7. #7
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    927

    Default Re: I need a widget that will display a random photo each time pages is loaded.

    Nice code sculptex.

    Egg, did you place the file and folder in the root? Does your sever support PHP?

    JDunn, what exactly do you need the widget to do? Should it center the random picture within the region of the placeholder or should it be stretched and if so should the aspect ratio be preserved?

  8. #8
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    17,823

    Info Re: I need a widget that will display a random photo each time pages is loaded.

    I don't think many have PHP skills or access.
    Here is a Xara solution with CSS and jQuery.

    Make a box of any size.

    • Name it viewer and add the special Name UsesJQuery
    • To its Placeholder Body add:

    Code:
    <script>
    $(document).ready(function(){
    
            var imgCount = $('.illy').length;
            var guessImg = Math.floor(Math.random() * imgCount + 1);
    
            $('.illy').hide();
            var imgUrl = $('.illy:nth-child(' + guessImg + ')').attr('src');
    
            $('#viewer').css({'background-image':'url(' + imgUrl + ')','background-repeat':'no-repeat','background-position':'center','background-size':'contain'});
    
    });
    
    </script>
    • Ensure the ​viewer box is the topmost object.


    Add any objects under viewer that you know render as images (text does not work - it has to be grouped).
    Given then all the Name htmlclass=illy.

    You can resize the viewer box and the illy objects will scale to fully fit.
    I chose to hide all the illy objects, but you can have them elsewhere on your site, on pages or layer (provided the layers are accessible).

    Example here: CSS3 & jQuery - Random Image on Load.xar

    In summary, create a viewer Widget somewhere on a page.
    Any (image) objects any where on your site with Name illy will appear randomly in the viewer on page load or refresh.

    Acorn
    Acorn - installed Xara software: Cloud+/Pro+ and most others back through time (to CC's Artworks). Contact for technical remediation/consultancy for your web designs.
    When we provide assistance, your responses are valuable as they benefit the community. TG Nuggets you might like. Report faults: Xara Cloud+/Pro+/Magix Legacy; Xara KB & Chat

  9. #9
    Join Date
    Apr 2012
    Location
    SW England
    Posts
    17,823

    Default Re: I need a widget that will display a random photo each time pages is loaded.

    Quote Originally Posted by siran View Post
    Should it center the random picture within the region of the placeholder or should it be stretched and if so should the aspect ratio be preserved?
    siran, in my go, I've assumed centring and scaling to fit the enclosing box. Both these features can be altered.

    Acorn
    Acorn - installed Xara software: Cloud+/Pro+ and most others back through time (to CC's Artworks). Contact for technical remediation/consultancy for your web designs.
    When we provide assistance, your responses are valuable as they benefit the community. TG Nuggets you might like. Report faults: Xara Cloud+/Pro+/Magix Legacy; Xara KB & Chat

  10. #10
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    927

    Default Re: I need a widget that will display a random photo each time pages is loaded.

    Hi Acorn,
    thought about a similar solution but decided to create a widget, just to get a little practice again...
    It turned out be be six widgets all about identical but in the way of scaling:

    widget_RndPicOnLoad_v1_0_center.xar - doesn't scale, just centers
    widget_RndPicOnLoad_v1_0_contain.xar - scales to fit inside (only works in IE9 and higher)
    widget_RndPicOnLoad_v1_0_cover.xar - scales to fully fill (only works in IE9 and higher)
    widget_RndPicOnLoad_v1_0_fill.xar - stretches to fully fill (looses aspect ratio)
    widget_RndPicOnLoad_v1_0_height.xar - scales to same hight
    widget_RndPicOnLoad_v1_0_width.xar - scales to same width

    How to use:
    Drag the widget of your choice to your document.
    Resize the placeholder to your needs.
    Double click the placeholder to change the pictures.
    Delete all but one page.
    Delete the picture from the remaining page.
    Drag in you own picture.
    Resize the page if required.
    Give it the name "WTag:image:image" (without the double quotes, you can select it from the list of existing names).
    If all your pictures are the same size you can give it the name "autoreplace" (also in the list) and then select and drag all your pictures on top of that image and Xara will create as many new pages as required.
    If your pictures are of differing size you should manually create a new page drag in a picture and give it the name for each of them.
    Save and you should be ready to preview.
    Attached Files Attached Files

 

 

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •