views:

43

answers:

4

hey guyz i have a function

 $result = create_watermark( 'input_file_name' ,'output_file_name');

i have dir called /images n have 500 images in it and all images are link images_(some_unknown_numbers).png (all png) now i want run them thru function in loop and want out put like /markedimage/images_1.png images_2.png images_3.png

i need help how can i run them in loop and how out put name can change

want run script on Ubuntu so we can use shell too

if any body want check function it is here

http://paste2.org/p/789149

plz provide me code because i m newbie

thanks in advance

A: 

I'm not sure whether you want to re-index the numbers for the output files. This example should preserve them:

<?php
$dir = './sourceDir';
$outputDir = './markedimage';

//get files matching pattern. maybe you could use glob() instead
$files = scandir($dir);
$files = preg_grep('~^images_\d+.png$~i', $files);

//process each file
foreach ($files as $file) {
     create_watermark( $dir . '/' . $file, $outputDir . '/' . $file);
}
Tom Haigh
+2  A: 
<?php

foreach (glob("*.png") as $filename) {
    create_watermark($filename, '/watermarked_dir/' . $filename);
}
DuoSRX
working for me without any change thankxx
Steve
A: 

Untested but this should work, too:

// Iterate over all filesystem objects in /images
foreach( new DirectoryIterator('/images') as $file ) {
    // check if item is a readable file
    if( $file->isFile() && $file->isReadable() ) {
        // give debug message so we know what the script is doing
        echo "Watermarking $file \n";
        // call your function
        create_watermark(
            // argument 1 is the full path to the image
            $file->getPathname(),
            // argument 2 is the destination folder plus the filename w/out path
            '/markedimage/' . $file->getFilename()
        );
    // tell us if it is not a readable file
    } else {
        echo "Skipped $file \n";
    }
}

If there is files in the folder that are not png files, you can use the GlobIterator instead of the DirectoryIterator, but that would require PHP5.3.

See

Gordon
A: 

hey i m Steve

i used 2nd answer

working one

<?php

foreach (glob("*.png") as $filename) {
    create_watermark($filename, '/watermarked_dir/' . $filename);
}
?>

this answer worked without any change :D thankx but i can't vote for it because i m not registered

@1 i m failed to make it working but this i think if put some effort on it it shud work

<?php
$dir = './sourceDir';
$outputDir = './markedimage';

//get files matching pattern. maybe you could use glob() instead
$files = scandir($dir);
$files = preg_grep('~^images_\d+.png$~i', $files);

//process each file
foreach ($files as $file) {
     create_watermark( $dir . '/' . $file, $outputDir . '/' . $file);
}

?>

thankx to guyz who tried and helped me allot i was try to do this from last 5 hours but failed her it solved in five minutes

:D thankxxx

Steve

Steve