Jump to content

Copy image with increase number


flemmingp

Recommended Posts

Hi all

 

 

I have this where I aplly filer to an webcam image

and save it...

 

BUT hov can I save it with numbers _0001.jpg , _0002.jpg

 

this is my code

$image = imagecreatefromjpeg($image);
  //imagefilter($image, IMG_FILTER_NEGATE);
  imagefilter($image, IMG_FILTER_BRIGHTNESS, 30);
  imagefilter($image, IMG_FILTER_CONTRAST, -10);  
  imagejpeg($image, 'cam-corrected.jpg');
  imagedestroy($image);
  echo '<img src="cam-corrected.jpg" alt="Image Effect Applied" />';

 

REGARDS

Link to comment
https://forums.phpfreaks.com/topic/276345-copy-image-with-increase-number/
Share on other sites

Get the filename of the image (without the extension) using pathinfo. Then find all images matching the earlier retrieved filename using glob. Sort the results in reverse order (high to low) using usort and grab the first one using array_shift, grab the number using substr and strrpos (pass _ as needle), convert to an integer using intval, increment, and generate the new filename using sprintf. Store it using file_put_contents.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.