0

I want to resize a image using server side script (eg: Smart Image Resizer ), so it will send request to a script called image.php

<img src="/image.php/media/bg.jpg?width=320&height=240"/>

So script will take image and its dimensions for cropping.Instead of sending request to image.php or any server scripting why cant i pass all the img src request to image.php automatically. Using .htaccess or something?

<img src="/media/bg.jpg?width=320&height=240"/>
 And some config should automatically take it in and pass this

to your image resizer script and return the image result. Is it possible?

Thanks

6
  • It's possible, but this will be very resource heavy, as every time you load the image it'll have to be re-generated on the server. Are you sure this is the best way to proceed? (I'd have thought at the very least you'd want to check for a cached version of the image at the same size.) Commented Jan 6, 2011 at 17:12
  • 2
    so why can't you just put a .htaccess inside the /media/ folder that redirects image requests to image.php? Commented Jan 6, 2011 at 17:13
  • Just a note, it's strongly recommended to still include the width/height attributes of img tags to decrease load time and help with browser layout during the absence of content (Especially now that the image is being generated and not just served. Commented Jan 6, 2011 at 17:17
  • Yes exactly. I have placed it into media directoy rewrite rule. Will it make any problem? Commented Jan 6, 2011 at 17:19
  • @Ela That is exactly what I would do. Just put a .htaccess inside the media directory and have it redirect all requests there to a php script. Then I would have the php script get the requested dimensions, check to see if there is a file that exists for that image in those dimensions (cached copy) and if so, display that, if not, resize and save to cache. Commented Jan 6, 2011 at 18:21

2 Answers 2

1

By automatically, do you mean on page load?

If so, i would use jQuery ajax to send the img to the image.php and display the returned image onto the page. Or am i completely misunderstanding your request?

Sign up to request clarification or add additional context in comments.

1 Comment

No no, I want the automatic request to a php script. Ajax calls will take time after image loaded in client side. I have added my update in answer. check it
0

yes i have got it.

I added this line in .htaccess

RewriteRule ^media/(.*).jpg$ image.php?src=$1 [L]

so when ever request comes into media directory with jpg extension all those will be passed to the image.php

Am i right? I ma trying this way.

Comments

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.