Jump to content

[SOLVED] Resizing images


gerkintrigg

Recommended Posts

For some reason, the resizing of images from my XML feed doesn't seem to work, so i was wondering whether it's an issue with the script I'm using.

 

I have a script that works fine with uploads, but cannot resize from a URL. Any help here?

 

Here's the code I use:

class SimpleImage {
   
   var $image;
   var $image_type;
// outputs e.g.  somefile.txt: 1024 bytes

   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);
      }
  if (filesize($filename)>=500){
$over_size='y';
}
   }
   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;   
   }      
}

 

And that works fine for uploads... when i use the following code in my web-pages:

   $image = new SimpleImage();
   $image->load($_FILES['image_upload']['tmp_name']);
   $image->resize(90,68);
   $image->save('images/small_'.$record_id.'.jpg');
   $my_small_image='images/small_'.$record_id.'.jpg';

 

The problem is when i use it from a url like this:

   $image = new SimpleImage();
   $image->load(http://www.myointernational.com/furniture/logo.jpg);
   $image->resize(90,68);
   $image->save('images/small_'.$record_id.'.jpg');
   $my_small_image='images/small_'.$record_id.'.jpg';

 

Any help?

Link to comment
https://forums.phpfreaks.com/topic/167767-solved-resizing-images/
Share on other sites

Warning: filesize() [function.filesize]: Stat failed for http://www.myointernational.com/furniture/logo.jpg (errno=2 - No such file or directory) in /hsphere/local/home/davetrig/myointernational.com/includes/img_resize.php on line 38

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.