0

I've noticed that usually, Wordpress will name a scaled image copy by appending the resolution, like this:

image1-200x200.jpg

Is this always the case? Are there any special circumstances where they would be named differently?

I ask because I have seen a few named after the image size name, like this:

image1-large.jpg

I'm trying to come up with a simple regex to only show original images, so I'd like to know what rules Wordpress follows when naming these files. Can anyone enlighten me?

1

yes, the naming convention for resized images is name-{width}x{height}.extension.

Is it good enough info to base a regex on? in practice most likely yes, but in theory no. You just can't know if mark-20x20.jpg was not simply uploaded that way, and even in places where you know that a resized image should be used you have no way to know if wordpress had decided that the best fitting image is the original. The proper way to know what is the original image based on image url is to search the attachments part of the DB for it which can be a little PITA (no simple API for it as far as I know).

  • thanks for confirming that - you are right about it being imperfect to base my regex on. And yes in this instance searching the wordpress DB would be a big PITA but for a correct result then it's worth it. Thanks for the thoughtful comments. – jammypeach Jan 21 '15 at 13:28
  • I actually ended up doing as suggested and connecting to the database to get a list of guids. It's the only way to go really, although having tested the regex approach it worked fine unless someone uploaded pic-100x100.jpg. – jammypeach Jan 26 '15 at 16:39

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.