masterexploder / PHPThumb

PHP Thumbnail & Image Manipulation Library
http://phpthumb.gxdlabs.com
980 stars 264 forks source link

Can i change the filename when save (via browser) ? #109

Open maykelesser opened 10 years ago

maykelesser commented 10 years ago

This is a request from a client of mine. For SEO purposes, somehow the file name to save the generated thumbnail is bothering him (when he save via browser).

I'm running the script generating the image using the following URL:

http://generacbrasil.com.br/common/function/thumb.php?url=testing-image.png&width=350&height=350&prefix=thm

But when I ask to save the image on my desktop for example, the name of the image you are saving is always "thumb.png".

Is there any way to save the image with its original name, or at least transform into thm_testing-image.png? captura de tela 2014-07-29 as 13 27 55

mikealmond commented 10 years ago

There really isn't anything you can do on the PHPThumb side for this. You could do a url rewrite so that /images/350/350/testing-image.png rewrites to /common/function/thumb.php?url=testing-image.png&width=350&height=350. That way the browser would try to save the file as testing-image.png and not thumb.png

In Apache it would look like this

# .htacecss
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^images/([1-9][0-9]{1,2})/([1-9][0-9]{1,2})/(.+)\.(jpg|png|jpeg)$ /common/function/thumb.php?url=$3.$4&width=$1&height=$2&prefix=thm [L]
</IfModule>

This would limit the width and height to the range 10...999 and the image extensions to either jpg, jpeg, or png.