user320487
user320487

Reputation:

How to display an image with URL parameters with PHP

I'm in the process of changing hosts and have ran into an issue displaying images. On the current host, images are served up with:

<img id="i1877" src="http://somewebsite.com/images/photo-shoots/XLIscjDrEAdkhzAeDsBrXIedV.jpeg?w=200&h=200">

However, on the new host, it won't accept the src attribute with the URL dimension parameters. All images are stored on the server in the path format:

/path/to/image/XLIscjDrEAdkhzAeDsBrXIedV.jpeg200x200
/path/to/image/XLIscjDrEAdkhzAeDsBrXIedV.jpeg500x500
/path/to/image/XLIscjDrEAdkhzAeDsBrXIedV.jpeg1000x1000

Is there an Apache2 mod or something that translates from the URL encoded src to the dimensions appended on the end of the filename? I've never seen a system set up like this and just inherited this project, so any help would be much appreciated! Thanks in advance!

Upvotes: 1

Views: 4141

Answers (2)

Hook4free
Hook4free

Reputation: 1

You have to check jQuery image resize solution which is front-end solution, but it will slow down site appearance. Another solution is php image resize function, which is available for free on the net. http://plugins.jquery.com/project/aeImageResize

Upvotes: 0

mattbasta
mattbasta

Reputation: 13709

The simplest means of doing this would be to set up a .htaccess file that intercepts all requests to the images in that folder, parses out the image name from the URL ($_SERVER["REQUEST_URI"] is your friend), and then use readfile() to actually output the correct JPEG based on $_REQUEST["w"] and $_REQUEST["h"].

Hope this helps!

Upvotes: 1

Related Questions