First, wasn't sure where to put this so I stuck it here because of the PHP files involved.

Any way, what would need to be written into my sites .htaccess file to "ping" a php file when an image is called ?

So if I type into my browser, a file at is ran.

Basically when image.jpg is called image.php should be ran to update the displayed images contents.

Edit: The below bit half works, it gets the images updated by hitting the associated php files but when I try to call the images they don't show but if I removed the below from my .htaccess the images work fine, what gives ?

RewriteEngine on
RewriteRule Nintendo3DS4free.jpg$ Nintendo3DS4free.php [L]

Recommended Answers

All 3 Replies

When you remove the RewriteRule from .htaccess, you are seeing the .jpg file. If the rule is active, you see the output of the PHP file which is something completely different.
You do not need this setup. Instead replace all references to the .jpg file by references to the .php file and let the script not only update the graphics but also display it. Use

header('Content-type: image/png');

I've since changed a few small things around to use less files since I have more than one image to play with. In any case, here is now what's in my .htaccess file.

RewriteEngine on
RewriteRule ^(.*).jpg$ ImageResize.php [L]

Now here is what's in the PHP file to be pinged when any image is called. The four things at the bottom is what controls the image stuff for the images I call. So, here's my question... to make your solution work for all images regardless of name as I may add more what would need to be done andd where in the PHP file, I'll assume I can leave my .htaccess stuff the way it is.

class SimpleImage {
   var $image;
   var $image_type;
   function load($filename) {
      $image_info = getimagesize($filename);
      $this->image_type = $image_info[2];
      if( $this->image_type == IMAGETYPE_JPEG ) {
         $this->image = imagecreatefromjpeg($filename);
      } elseif( $this->image_type == IMAGETYPE_GIF ) {
         $this->image = imagecreatefromgif($filename);
      } elseif( $this->image_type == IMAGETYPE_PNG ) {
         $this->image = imagecreatefrompng($filename);
   function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
      if( $image_type == IMAGETYPE_JPEG ) {
      } elseif( $image_type == IMAGETYPE_GIF ) {
      } elseif( $image_type == IMAGETYPE_PNG ) {
      if( $permissions != null) {
   function output($image_type=IMAGETYPE_JPEG) {
      if( $image_type == IMAGETYPE_JPEG ) {
      } elseif( $image_type == IMAGETYPE_GIF ) {
      } elseif( $image_type == IMAGETYPE_PNG ) {
   function getWidth() {
      return imagesx($this->image);
   function getHeight() {
      return imagesy($this->image);
   function resizeToHeight($height) {
      $ratio = $height / $this->getHeight();
      $width = $this->getWidth() * $ratio;
   function resizeToWidth($width) {
      $ratio = $width / $this->getWidth();
      $height = $this->getheight() * $ratio;
   function scale($scale) {
      $width = $this->getWidth() * $scale/100;
      $height = $this->getheight() * $scale/100; 
   function resize($width,$height) {
      $new_image = imagecreatetruecolor($width, $height);
      imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
      $this->image = $new_image;   

	$image1 = new SimpleImage();

	$image2 = new SimpleImage();

	$image3 = new SimpleImage();

	$image4 = new SimpleImage();

I'd rather let you tell us what does not work and how it is supposed to work than digging through all your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.