Page 1 of 1

Replacing Thumbnail Dimensions

Posted: Wed Jun 08, 2011 9:54 am
by psurrena
Hello,

I'm replacing the 525x272 of the following url with 236x190.
http://www.website.com/wp-content/uploa ... 25x272.jpg

I'm using the following pattern but how should I modify it so it works when there are only two numbers or maybe four?

Code: Select all

preg_replace('/[0-9][0-9][0-9]x[0-9][0-9][0-9]/m', "236x190", $image['full'])
Thanks!

Re: Replacing Thumbnail Dimensions

Posted: Wed Jun 08, 2011 10:06 am
by pickle
Your URL only has 2 numbers - why would there be 4?

Also - if you know the string your replacing, it'd be better to use str_replace()

Re: Replacing Thumbnail Dimensions

Posted: Mon Jun 27, 2011 7:47 pm
by twinedev
I if understand correctly, by having two or 4 digits, you mean the following:
  1. the-image-1024x768.jpg
  2. the-image-131x99.jpg
I believe the following is what you would be looking for:

Code: Select all

preg_replace('/-[0-9]+x[0-9]+\./', '-236x190.', $image['full'])
I included the preceding hyphen and the following period to help limit the matching to a more specific location (ie. what if someone uploads an file whose name already has dimensions, say my-pic-22x33-size-525x272.jpg )

-Greg