How to check image file in Perl?

How can I verify that the jpg file is a valid image file. We have files written to the directory using FTP, but we seem to be collecting the file before it has finished writing, creating invalid images. I need to determine when it is no longer being recorded. Any ideas?

+4
source share
5 answers

The easiest way is to simply write the file to a temporary directory, and then move it to the real directory after recording is complete.

Or you can check here .

JPEG :: Error

[arguments: none] If the link to the file remains undefined after a new file is called, this file should be considered undetectable by this module, and you should issue some error message and go to another file. An error message explaining the reason for the failure can be repaired using the Error method:

EDIT:

Image :: TestJPG might be even better.

+4
source

I think you are solving the wrong problem.

What you have to do is figure out how to say when any FTPd that you use is writing the file - so when you encounter the same problem for (say) GIF, DOC or MPEG, you need to fix it again .

Exactly how you do it, it pretty much depends on which FTPd is running on which OS. Some, I believe, have hooks that you can configure when it boots.

If you can run your own FTPd, Net :: FTPServer or POE :: Component :: Server :: FTP are configured to work properly.

In the absence of this:

1) try closing logs with a Perl script that looks for download completion messages 2) use something like lsof or fuser to check if something is blocking the file before trying to copy it.

+4
source

Consider the FTP problem again, not the JPG problem.

I check the timestamp in the file to make sure that it has not been changed in the last X (5) minutes - this way I can be sure that they have finished loading

 # time in seconds that the file was last modified my $last_modified = (stat("$path/$file"))[9]; # get the time in secs since epoch (ie 1970) my $epoch_time = time(); # ensure file not been modified during the last 5 mins, ie still uploading unless ( $last_modified >= ($epoch_time - 300)) { # move / edit or what ever } 
+1
source

I had something similar that appeared once, more or less what I did:

 var oldImageSize = 0; var currentImageSize; while((currentImageSize = checkImageSize(imageFile)) != oldImageSize){ oldImageSize = currentImageSize; sleep 10; } processImage(imageFile); 
0
source

The FTP process has the readonly flag set, and then it only works with files with the readonly flag set.

0
source

All Articles