SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    slideshow: glob issue?

    Got this slideshow script from a third party and made some modifcations to work with php 4.3. No php error has came up, but no "slideshow" images have come up. I'm still new to php stuff and I gather that the problem may lies with the glob function since it seems not sending the image paths to other functions to process the slideshow. Am I right?

    Code:
    <?php
    
    // open the folder and locate the files end with .jpg
    $dh = glob( "blah/blah" );
    
    $files = array();
    foreach( $dh as $file )
    {
      if ( preg_match( "/[.]jpg$/", $file ) ) $files []= "$file";
    }
    ?>
    In case the glob function is right, other functions below:
    Code:
    <script>
    // list images
    var image_list = [
    <?php $first = true; foreach( $files as $image ) { ?>
    <?php echo( $first ? "" : ", " ); ?>"<?php echo( $image ); ?>"
    <?php $first = false; } ?>
    ];
    
    var curimage = 0;
    
    // grab and resize image
    function switchimg( ind )
    {
      var image = image_list[ind];
      var obj = document.getElementById( "selimg" );
      obj.src = "scale.php?image="+image+"&y=230";
      curimage = ind;
    }
    
    // next image
    function nextimage()
    {
      curimage++;
      if ( curimage >= image_list.length ) curimage = 0;
      switchimg( curimage );
    }
    
    // timer
    window.setInterval( "nextimage()", 3000 );
    </script>
    html output:
    Code:
    <img id="selimg" height="230" src="scale.php?image=<?php echo($files[0]); ?>&y=230" />
    scale.php:
    Code:
    // get current image and resize
    <?php
    $image = $_GET["image"];
    $maxy = $_GET["y"];
    
    $im = @imagecreatefromjpeg( "blah/blah/".$image );
    $curx = imagesx( $im );
    $cury = imagesy( $im );
    $ratio = $maxy / $cury;
    $newx = $curx * $ratio;
    $newy = $cury * $ratio;
    
    $oim = imagecreatetruecolor( $newx, $newy );
    imageantialias( $oim, true );
    imagecopyresized( $oim, $im, 0, 0, 0, 0,
    	$newx, $newy, $curx, $cury );
    
    header( "content-type: image/jpeg" );
    imagejpeg( $oim );
    ?>

    jace

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In scale.php:

    // get current image and resize

    ^^that needs to be inside the PHP tags otherwise it causes output and you get a 'Cannot modify header information' error.


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
  •