Jump to content

ndefontenay

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ndefontenay's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Having seen others presentation, I've decided to broaden up a bit on mine. I'm born in Mauritius (google map is your friend for this one). My name sounds reaaaaally french. That's because it is. I'm french origin but not french though. It took me 6 months worth of paper work 2 years ago to go work in Paris, so I can't really tell I'm one of them. I do speak french fluently. My wife is korean/american and I have 2 step daughters. I'm currently working on my spouse visa to the US and I should move to San Diego next year around june if all is fine. Before that I spent 7 years in Asia, moving around between China, Japan, Singapore and Thailand where i lived. I hope I will be able to contribute more than I learn as I get better with php. I don't think I'm a beginner. I can write fairly advanced code but I struggle a bit too due to my short experience with php.
  2. Thanks for the quick reply. True. I'm sorry about that. It's a bit hard to explain without actually showing the picture. I think a picture would explain better than a thousand words. If you've seen the picture: 1) I got the same thing going on for medium size pictures. 2) Then I check for mini size pictures and perform the same task For medium it works fine, for mini I got the weird result. [attachment deleted by admin]
  3. Hi, I wrote a classFile to handle files that looks like this: class classfile { //path_parths is an array, use it this way //path_parts["filename"] -> filename //path_parts["dirname"] -> directory //path_parts["extension"] //path_parts["basename"] protected $path_parts; private $fullpath; function __construct($filename){ if(file_exists($filename)){ $this->fullpath = $filename; $this->path_parts= pathinfo($this->fullpath); } else{ die("File or Folder doesn't exist"); } } function move($destination){ if (file_exists($destination)){ rename($this->fullpath, $destination . "/" . $this->getfilename()); //Update properties $this->setfullpath($destination . $this->getfilename()); $this->setpath_parts(); } else{ die("The folder specified doesn't exist"); } } function copy($destination){ copy($this->fullpath, $destination); } function getpath(){ return $this->path_parts["dirname"]; } function getfilename(){ return $this->path_parts["basename"]; } function getextension(){ return $this->path_parts["extension"]; } function getfullpath(){ return $this->fullpath; } function setfullpath($path){ $this->fullpath = $path; } function setpath_parts(){ $this->path_parts = pathinfo($this->fullpath); } function __destruct() { ; } } ?> Then I extended it with a class to handle images that looks like this: include 'c:/wamp/www/classfile.php'; class classimage extends classfile{ var $image; var $image_info; var $image_type; function __construct($filename){ parent::__construct($filename); $this->image_info = getimagesize(parent::getfullpath()); $this->image_type = $this->image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg(parent::getfullpath()); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif(parent::getfullpath()); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng(parent::getfullpath()); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=80, $permissions=777) { 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 $this->image_info[0]; } function getHeight() { return $this->image_info[1]; } 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); echo "resized to:\n"; echo $width . "\n"; echo $height . "\n"; echo "imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight())\n"; imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } function format(){ $width = $this->getWidth(); $height = $this->getHeight(); if ($width > $height){ return "landscape"; } if ($height > $width){ return "portrait"; } if ($height == $width){ return "square"; } } function isTooBig($maxsize){ $width = $this->getWidth(); $height = $this->getHeight(); if ($width > $maxsize || $height > $maxsize){ return true; } else{ return false; } } function __destruct() { ; } } ?> Now that I got this, I loop through images located in a folder that way: if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { //Instantiate the object $image = new classimage($directory . "/" . $file); //And do quite a lot of verification and particularly this: if ($image->format() == "landscape") { echo "width: " . $image->getWidth() . "\n"; echo "height: " . $image->getHeight() . "\n"; if ($image->isTooBig($maxsize_mini)) { $image->resizeToWidth($maxsize_mini); $image->save($directory . "/mini_" . $image->getfilename()); } } } And now to the problem: I echo'ed the resize function to see what's being run and I got that: picture1 imagecopyresampled(Resource id #26, Resource id #25, 0, 0, 0, 0, 608, 405.65, (), ()) picture2 imagecopyresampled(Resource id #27, Resource id #26, 0, 0, 0, 0, 250, 166.796875, (), ()) It looks like it's reusing an instantiation of the previous object and so on and so forth. In my mind, the way it should look is: picture1 imagecopyresampled(Resource id #2, Resource id #1, 0, 0, 0, 0, 608, 405.65, (), ()) picture2 imagecopyresampled(Resource id #2, Resource id #1, 0, 0, 0, 0, 250, 166.796875, (), ()) The previous object is destructed, the new one has the old id. how does that work? The reason I ask and wonder about this is because I'm having weird result for the resize such as a ridiculously small picture mini size in the actual mini size picture (250 px) except whatever is left is filled with black.
  4. Hi guys, I'm not originally a php developer but I've been in the web business for the last 2 years as a database administrator production and data warehouse. I dip my hand a lot in system administration as well. I'm not new to algorithm and development. PHP is however. I favor Oriented Object a lot and php5 is giving me a lot of pleasure. Like everything however, to get better I need the expertise of others, better than me (which should be easy).
×
×
  • 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.