andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Code stops after converting 5 o6 pictures

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Drop Shadowed Thumbnail Creator
View previous topic :: View next topic  
Author Message
Leh00
Newbie


Joined: 17 Apr 2005
Posts: 5

PostPosted: Sun Apr 17, 2005 9:22 am    Post subject: Code stops after converting 5 o6 pictures Reply with quote

Hi there Andy,

I love your drop shadowed thumbnail class and I'm trying to get it work but I got stucked now... Crying or Very sad

I uploaded some original jpeg pictures to my webserver and I would like to convert all pictures in the specified source directory to the thumbnail folder. My code works fine till it has converted 5 or 6 pictures - then it stops converting... Is there a timeout who has to be set? Average picture size is 2-3mb, php post is set to

that's what I did:
PHP:
<?php
   
// Default settings
   
$maxWidth 0;
   
$maxHeight 200;
    
    
//Define picture dir
    
$localDir $_SERVER['DOCUMENT_ROOT']."bild$/amnuts/images/";
     
$UseImageType = array ("jpg""jpeg""JPG""JPEG");
    
//Open localDir
   
$pd opendir($localDir);
   while (
false !== ($filename readdir($pd))) {
       
$PicfileArray[] = $filename;
   }

    require 
"class.dropshadow.php";
   
       foreach (
$PicfileArray as $SourceImages) {
        
$FileExt substr($SourceImagesstrpos($SourceImages".")+1strlen($SourceImages));
        if( 
in_array($FileExt$UseImageType) ) {
            
$ds = new dropShadow(false);
            
$ds->setShadowPath('./shadows/');
            echo 
"Converting: ".'./images/'.$SourceImages.'<-<br>';
            
$ds->loadImage('./images/'.$SourceImages);
            
$ds->resizeToSize($maxHeight $maxWidth);
            
$ds->applyShadow('FFFFFF');
            
$ds->saveShadow('./Thumbnails/Thumb_'.$SourceImages);
            
//$ds->showShadow('png');
        
}
    }
?>


Thanks a lot for helping!

Regards

Leh00
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Apr 18, 2005 2:54 am    Post subject: Reply with quote

Hi, and welcome to the board!

The script could have stopped working for a couple of reasons. The first might be that it had run out of memory and the second might be the timeout length for the script was hit. Both are PHP controlled, though you can adjust them on the fly.

In your script you were creating an instance of the class for every image. This meant that you had all of your pictures in memory, adding a new one everytime that you created a new instance of the class. A better way would be to create one instance and then flush out the images once you're done with it. Like so:

PHP:
<?php

    
// Default settings
    
$maxWidth 0;
    
$maxHeight 200;
    
    
//Define picture dir
    
$localDir $_SERVER['DOCUMENT_ROOT'] . 'bild$/amnuts/images/';
    
$UseImageType = array('jpg''jpeg');
    
    
//Open localDir
    
$pd opendir($localDir);
    while (
false !== ($filename readdir($pd))) {
        
$FileExt strtolower(substr($filenamestrpos($filename'.')+1strlen($filename)));
        if (
in_array($FileExt$UseImageType)) {
            
$PicfileArray[] = $filename;
        }
    }
    
closedir($pd);

    require(
'class.dropshadow.php');
    
$ds = new dropShadow(false);
    
$ds->setShadowPath('./shadows/');
   
    foreach (
$PicfileArray as $SourceImages) {
        echo 
'Converting: ./images/'$SourceImages'<-<br>';
        
$ds->loadImage('./images/' $SourceImages);
        
$ds->resizeToSize($maxHeight$maxWidth);
        
$ds->applyShadow('FFFFFF');
        
$ds->saveShadow('./Thumbnails/Thumb_' $SourceImages);
        
$ds->flushImages(0);
        
$ds->flushImages(1);
        
$ds->flushImages(3);
    }

?>


Flushing those three images will remove the originally loaded image, the final (resized) image and the shadowed image. It will keep everything else in memory for use.

Okay, try that out for the memory issues and see if it works.

If you're getting timed out then PHP should be showing you some kind of error message on screen. You can adjust that by using the set_time_limit function in PHP. You can do this in a loop, if you want, to always extend your time limit for processing.

http://www.php.net/set_time_limit

If you are still having problems with memory, then you could try increasing that... ini_set('memory_limit', '8M'); if what you need, I think... Obviously changing '8M' to whatever you want (that's 8MB). But try out the above code first and see if that works for you, then the time limit if that's your problem.

HTH

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Leh00
Newbie


Joined: 17 Apr 2005
Posts: 5

PostPosted: Mon Apr 18, 2005 4:16 am    Post subject: Reply with quote

Hi Andy,

thanks for your fast answer... I will check it out an give you feedback how it worked...

Regards

Hanspeter

PS: Check your Paypal account Cool
Back to top
View user's profile Send private message
Leh00
Newbie


Joined: 17 Apr 2005
Posts: 5

PostPosted: Mon Apr 18, 2005 1:49 pm    Post subject: Reply with quote

Andy,

it works perfect - I forgot to adjust the timeout in PHP while in http.conf I did it...

Just one thing is missing:
I do not get any feedback while this script is running - the message "Converting: ./images/DSC00273.JPG<-" etc. I receive them all together at the end of the process...

The user might think the script does not run correctly because of no feedback while creating the thumbnails...

Any help is appreciated

Hanspeter
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Apr 18, 2005 1:58 pm    Post subject: Reply with quote

I'm glad you've got it working!

You could try flushing the text after you've output it, like:

PHP:
<?php echo 'Converting: ./images/'$SourceImages'<-<br>';
flush(); ?>


That'll force the output to the screen rather than waiting 'til the end for an implicit flush.

Andy

btw; I hope you got my email... If not; thanks very much for the donation! Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Leh00
Newbie


Joined: 17 Apr 2005
Posts: 5

PostPosted: Tue Apr 19, 2005 12:32 pm    Post subject: Reply with quote

Hi there Andy,

yes - I got your mail Very Happy

But there is still no feedback... Hmmm... Confused

I am the first one doing the conversion of an entire directory ? - or at least I do not have success jet with the feedback... Laughing

Regards

Hanspeter
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Tue Apr 19, 2005 5:20 pm    Post subject: Reply with quote

Hmm... Are you buffering the output at all with ob_start()? If so, that might be affecting you. If not, post up the code you have so we can have a look at it. If you don't want to post it up, then PM me with it and I'll get back to you if I spot anything.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Leh00
Newbie


Joined: 17 Apr 2005
Posts: 5

PostPosted: Wed Apr 20, 2005 12:30 am    Post subject: Reply with quote

Andy,

the code is somehow still the same. I added just the flush();

I'm doing something in a wrong way? I guess it's common to convert uploaded pictures...

Specialy when you upload pictures from a 8MB digi cam -> it takes for ever (~10 sek per picture) and without printing any hint's you feel like having an crashed webserver... A simple "please wait - pictures are importet is not enough"

Regards

Hanspeter
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Drop Shadowed Thumbnail Creator All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group