SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist -Oz-'s Avatar
    Join Date
    Nov 2001
    Location
    Phoenix, AZ, USA
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Imagecopyresampled timesout in loop, progress bar?, refreshing loop

    I have created a script that allows you to drag and drop 100s of images which are then uploaded, watermarked, and resized. The problem is during the processing of the images the script times out. It I use imagecopyresized it works but the quality is too crappy. I need the ability to process all the images without the user "quitting" so I'd like to have a processing text/image and/or progress bar.

    Here are some possible solutions I've kind of come up with but cannot figure out how to code:

    • Progress bar during processing (like this thread) it doesn't work I think because i'm not using an exec command.
    • Do refreshes until all images have been processed. In this case process an image, refresh, process the next, etc. until its done. during this process i'd like to display something to the user, a progress bar, a count, anything (i can probably figure this out if someone can tell me how i'd do the looping refreshing).
    The files are upload via jupload ( http://www.jupload.biz ) then processed in a php script. Here is the script that does the processing:
    PHP Code:
    foreach($_FILES as $tagname=>$objekt)
     {
      
    $x++;
      
    // get the temporary name (e.g. /tmp/php34634.tmp)
      
    $tempName $objekt['tmp_name'];
      
      
    $realName time() . $x ".jpg"
      
    $thumbName time() . $x "t.jpg"
      
      
    // print something to the user
      
    echo "<br>Processing file $x ($realName)...\n";
      
    flush();
         
          
    //WATERMARKED
          
    $src_img imagecreatefromjpeg($tempName);
          
    $origw=imagesx($src_img); 
          
    $origh=imagesy($src_img); 
          
    $new_w '700';
          
    $ratio=$origh*$new_w
          
    $new_h=$ratio/$origw
          
    $dst_img imagecreatetruecolor($new_w,$new_h); 
          
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); 
             
    $insertfile_id imageCreateFromPNG("watermark.png");
             
    $insertfile_width=imageSX($insertfile_id); 
             
    $insertfile_height=imageSY($insertfile_id);
             
    $dest_x $new_w $insertfile_width//removed a -5
             
    $dest_y $new_h $insertfile_height//removed a -5
             
    imageCopyMerge($dst_img$insertfile_id,$dest_x,$dest_y,0,0,$insertfile_width,$insertfile_height,60);
          
    $thumb_target './uploaded/' $realName;
          
    imagejpeg($dst_img$thumb_target); 
         
          
    //THUMBNAIL
          
    $src_img imagecreatefromjpeg($tempName);
          
    $origw=imagesx($src_img); 
          
    $origh=imagesy($src_img); 
          
    $new_w '150';
          
    $ratio=$origh*$new_w
          
    $new_h=$ratio/$origw
          
    $dst_img imagecreatetruecolor($new_w,$new_h); 
          
    imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img)); 
          
    $thumb_target './uploaded/' $thumbName;
          
    imagejpeg($dst_img$thumb_target);
     
      
    // end of iteration
      
    echo "next file...\n";
      
    flush();
     } 
    I think it is supposed to write Processing image... do the processing, then say next file, processing. But it doesnt it tries to do it all then display the results but it takes longer than 30seconds and times out. I don't want to just blindly increase the allowed processing time because it could be a long time if they upload 500 or so images.

    Any ideas and or help would be greatly appreciated. I'd even be willing to paypal someone $5-$10 if they have a solution but don't want to share it without compensation. (i could just give you the entire "system" too).

    TIA
    Oz
    GamersMark - On Target Gaming
    OzTheory - Programming and Web Solutions
    AmIBlocked - Check if you've been blocked on IM

  2. #2
    SitePoint Enthusiast Navin's Avatar
    Join Date
    Jun 2005
    Location
    St. Petersburg [ru]
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    -Oz-,

    PHP Code:
    <?php

    set_time_limit
    (0);

    /* Your script goes here */

    ?>
    Safe Mode must be Off.
    http://navin.biz - ASP.NET C# Ninja

  3. #3
    SitePoint Enthusiast Navin's Avatar
    Join Date
    Jun 2005
    Location
    St. Petersburg [ru]
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also you may want to look at PEAR::Progressbar package. It has descriptive manual on how to integrate it into your application.
    http://navin.biz - ASP.NET C# Ninja

  4. #4
    SitePoint Zealot allstar's Avatar
    Join Date
    Sep 2005
    Location
    in my box.
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Store the tmp file names in a mysql db. Then when a certain number of loops happens then just header('file.php?start=xxx&end=xxx');


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
  •