0

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 mysite.com/image.jpg into my browser, a file at mysite.com/image.php 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]

Edited by MoreBloodWine: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by smantscheff
0

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');
  readfile('Nintendo3DS4free.jpg');
0

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.

<?php
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 ) {
         imagejpeg($this->image,$filename,$compression);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image,$filename);         
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image,$filename);
      }   
      if( $permissions != null) {
         chmod($filename,$permissions);
      }
   }
   function output($image_type=IMAGETYPE_JPEG) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image);         
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image);
      }   
   }
   function getWidth() {
      return imagesx($this->image);
   }
   function getHeight() {
      return imagesy($this->image);
   }
   function resizeToHeight($height) {
      $ratio = $height / $this->getHeight();
      $width = $this->getWidth() * $ratio;
      $this->resize($width,$height);
   }
   function resizeToWidth($width) {
      $ratio = $width / $this->getWidth();
      $height = $this->getheight() * $ratio;
      $this->resize($width,$height);
   }
   function scale($scale) {
      $width = $this->getWidth() * $scale/100;
      $height = $this->getheight() * $scale/100; 
      $this->resize($width,$height);
   }
   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();
	$image1->load('http://www.YourFreeNetbook.com/goods/16824548.png');
	$image1->resize(340,85);
	$image1->save('images/YourFreeNetbook.jpg');

	$image2 = new SimpleImage();
	$image2->load('http://www.Nintendo3DS4free.com/goods/16824176.png');
	$image2->resize(340,85);
	$image2->save('images/Nintendo3DS4free.jpg');

	$image3 = new SimpleImage();
	$image3->load('http://www.YouriPad4free.com/goods/16824532.png');
	$image3->resize(340,85);
	$image3->save('images/YouriPad4free.jpg');

	$image4 = new SimpleImage();
	$image4->load('http://www.YourNintendoWii4Free.com/goods/14904127.png');
	$image4->resize(340,85);
	$image4->save('images/YourNintendoWii4Free.jpg');
?>
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.