0

I am working with wordpress images that the user chooses. They may or may not have been resized by wordpress and have their size added on to the end of the image like so:

original image: image.jpg wordpress version: image-300x200.jpg

How would I search to see if the image has this added to it? The easiest way would be to check if it has an 'x' 8 characters from the end of the variable but then there is the off chance that the image could actually have an x in it there.

1 Answer 1

1

thy this:

$is_resized=preg_match('|^.*-[0-9]{1,4}x[0-9]{1,4}\..*$|',$imagename)
Sign up to request clarification or add additional context in comments.

4 Comments

Oh thank you. One more question, how would I add a string 4 characters from the end of another string?
Only problem is it might not be .jpg, it could be .png or .gif
if you read carefully all answers of the link i gave , some are more generic. moreover, by replacing the .*$ part of the regexp i gave you by (.*)$ and using the $matches param of preg_match, you'll get the image extension and could be able to perform a seach for insert with it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.