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
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.

Edited by ignace
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.