title: How can I grab an image from another site using PHP or .htaccess?
body: <p>Ok, here is what I'm trying to do.</p>
  
  <p>On my site, I have a set of images I've uploaded to use as my avatar. Those sites usually asks for different sizes and are very picky to what kind of URLs they accept.</p>
  
  <p>What I'm trying to do is to get a Gravatar image, from the Gravatar server, and serve it using a customized URL, on the fly or with cache.</p>
  
  <p>My Gravatar URL for an image 100x100px:</p>
  
  <pre><code>http://gravatar.com/avatar/b6e428090e62182266a4e9dd87297ee1.png?s=100
  </code></pre>
  
  <p>What I want to offer to websites, more or less:</p>
  
  <pre><code>http://alenonimo.com.br/avatar/avatar100.png
  </code></pre>
  
  <p>Now let me explain the issue I'm trying to solve here, because it's interesting.</p>
  
  <p>Some sites accepts third party URLs for avatar images, like phpBB and the like. They also have different sizes they prefer, like 100x100 pixels, 120x120 pixels, 200x200 pixels, etc. Yet, they refuse to accept the Gravatar URL if it comes with the "s" variable on the URL, which defines the size of the images served from Gravatar. The default size is always 80x80 pixels without the option.</p>
  
  <p>So I want to serve those sites the Gravatar images and defining the size on the URL, in a way it doesn't notice that's coming from Gravatar's image generator. I want those sites to think the image actually comes from my website. It would allow me to set the size for those sites that doesn't accept Gravatar and luckily allow me to change all the avatar images on all those sites at once by just going to Gravatar.</p>
  
  <p>I'm pretty sure it could be done using Apache's RewriteEngine, yet I lack the code-fu to do it. All the examples that I've found on the net regards redirecting content from the same site to somewhere else on the same site, which is not the case. I also wanted to make sure the size attribute would be a more or less valid number, instead of accepting anything. So a file called "100.png" would be okay but "banana.png" would not.</p>
  
  <p>This for itself would be interesting but it occured me another thing. What if the site doesn't accept PNG files but accept JPG or GIF files? Probably wouldn't happen on sites which just show images but it would be interesting for me if I also could offer images to sites which uploads from URLs too. Also, maybe making sure something shows up even if Gravatar goes offline would be interesting too, like a cache system. That could be achievable with PHP but I'm not sure how complicated it would be.</p>
  
  <p>Could someone help me with the RewriteEngine rules? Or even giving me some pointer on how to make this PHP script? Would it be interesting to someone else in here?</p>