Albana_12 Posted August 21, 2012 Share Posted August 21, 2012 Hi everyone, i posted this once but i wasn't clear then. Please i have this code which generates me two images. what it does actually is generating me images like this: the first one: small_test.jpg.JPG the second one: test.jpg.JPG What i need is: the first one to generate me: test_s.jpg and the second one just: test.jpg this needs some changes in the functions, please help me with this, i've been struggling for 3 days now, i'm not an expert... function setFile($src = null) { $this->ext = strtoupper(pathinfo($src, PATHINFO_EXTENSION)); if(is_file($src) && ($this->ext == "JPG" OR $this->ext == "JPEG")) { $this->img_r = ImageCreateFromJPEG($src); } elseif(is_file($src) && $this->ext == "PNG") { $this->img_r = ImageCreateFromPNG($src); } elseif(is_file($src) && $this->ext == "GIF") { $this->img_r = ImageCreateFromGIF($src); } $this->img_w = imagesx($this->img_r); $this->img_h = imagesy($this->img_r); } function resize($largestSide = 100) { $width = imagesx($this->img_r); $height = imagesy($this->img_r); $newWidth = 0; $newHeight = 0; if($width > $height){ $newWidth = $largestSide; $newHeight = $height * ($newWidth / $width); }else{ $newHeight = $largestSide; $newWidth = $width * ($newHeight / $height); } $this->dst_r = ImageCreateTrueColor($newWidth, $newHeight); imagecopyresampled($this->dst_r, $this->img_r, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); $this->img_r = $this->dst_r; $this->img_h = $newHeight; $this->img_w = $newWidth; } function createFile($output_filename = null) { if($this->ext == "JPG" OR $this->ext == "JPEG") { imageJPEG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext, $this->quality); } elseif($this->ext == "PNG") { imagePNG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext); } elseif($this->ext == "GIF") { imageGIF($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext); } return $output_filename; } function setUploadDir($dirname) { $this->uploaddir = $dirname; } function flush() { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; $filename = $_FILES['Filedata']['name']; $ext = pathinfo($filename, PATHINFO_EXTENSION); $thumbnail = basename($filename,'.' .$ext) . '_s.' . $ext; imagedestroy($this->dst_r); unlink($targetFile); imagedestroy($this->img_r); } } $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; $filename = $_FILES['Filedata']['name']; $ext = pathinfo($FileName, PATHINFO_EXTENSION); $thumbnail = basename($FileName,'.' .$ext) . '_s.' . $ext; move_uploaded_file ($tempFile, $targetFile); $image = new Image(); $image->setFile($targetFile); $image->setUploadDir($targetPath); $image->resize(640); $small_file = $image->createFile('small_'.$filename); $image->resize(100); $large_file = $image->createFile($filename); $image->flush(); } Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/ Share on other sites More sharing options...
ialsoagree Posted August 21, 2012 Share Posted August 21, 2012 Change: function createFile($output_filename = null) { if($this->ext == "JPG" OR $this->ext == "JPEG") { imageJPEG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext, $this->quality); } elseif($this->ext == "PNG") { imagePNG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext); } elseif($this->ext == "GIF") { imageGIF($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext); } return $output_filename; } To: function createFile($output_filename = null) { if($this->ext == "JPG" OR $this->ext == "JPEG") { imageJPEG($this->dst_r, $this->uploaddir.$output_filename, $this->quality); } elseif($this->ext == "PNG") { imagePNG($this->dst_r, $this->uploaddir.$output_filename); } elseif($this->ext == "GIF") { imageGIF($this->dst_r, $this->uploaddir.$output_filename); } return $output_filename; } Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371153 Share on other sites More sharing options...
Albana_12 Posted August 21, 2012 Author Share Posted August 21, 2012 Hey thanks for your reply! My problem is that if i do that, this wouldn't work! $small_file = $image->createFile($filename); This is what i'm struggling about! Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371154 Share on other sites More sharing options...
ialsoagree Posted August 21, 2012 Share Posted August 21, 2012 Hey thanks for your reply! My problem is that if i do that, this wouldn't work! $small_file = $image->createFile($filename); This is what i'm struggling about! Why won't it work? Can you provide more detail? Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371155 Share on other sites More sharing options...
Albana_12 Posted August 21, 2012 Author Share Posted August 21, 2012 Yes, i mean, it won't create the file if i edit the code like you said! It just won't create it, no errors or something! Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371165 Share on other sites More sharing options...
ialsoagree Posted August 21, 2012 Share Posted August 21, 2012 Please run your script with this modification: function createFile($output_filename = null) { if($this->ext == "JPG" OR $this->ext == "JPEG") { echo "<br>imageJPEG( , $this->uploaddir . $output_filename , $this->quality );</br>"; } elseif($this->ext == "PNG") { echo "<br>imagePNG( , $this->uploaddir . $output_filename );</br>"; } elseif($this->ext == "GIF") { echo "<br>imageGIF( , $this->uploaddir . $output_filename );</br>"; } return $output_filename; } Copy the echoed line from your browser after running the code and post back here. Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371184 Share on other sites More sharing options...
ialsoagree Posted August 21, 2012 Share Posted August 21, 2012 Wait a second, in your reply to me you wrote this is your problem: $small_file = $image->createFile($filename); But in your original code you wrote it like this: $small_file = $image->createFile('small_'.$filename); $image->resize(100); $large_file = $image->createFile($filename); Obviously $small_file = $image->createFile($filename); isn't going to seem to work because $large_file = $image->createFile($filename); will just overwrite it. That's why you were doing $small_file = $image->createFile('small_'.$filename); in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371188 Share on other sites More sharing options...
Albana_12 Posted August 21, 2012 Author Share Posted August 21, 2012 Well, sorry i might have confused things, but remains the fact that it still won't work...! Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371189 Share on other sites More sharing options...
ialsoagree Posted August 21, 2012 Share Posted August 21, 2012 Well, sorry i might have confused things, but remains the fact that it still won't work...! Posting "it won't work" doesn't tell me anything useful. I gave you another code to try, did you try it? Where is the echoed text that I asked you to provide? It's important that you post the code you're running. If you don't post the code you're running, how am I suppose to know you just posted something else? You need to take the time to provide me with useful information. You said it doesn't give you an error or anything - well surely it did something. You're the only one who can look to see what it might have done. If you come back and tell me it "doesn't work," all thats left for me to do is shrug my shoulders and wish you the best in figuring it out. Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371191 Share on other sites More sharing options...
Mahngiel Posted August 21, 2012 Share Posted August 21, 2012 Why rename the image at all? you should instead call the thumbnail directory when you want a thumb vs full size. It'll also save you from a query call or table overpopulation assets/ >images/ >>thumbs/ >css/ >js/ define('IMAGES', '/path/to/assets/images/'); $image = 'cool_pic.png'; <img src= <?php echo IMAGES . $image;?> /> <img src= <?php echo IMAGES . 'thumbs/' . $image;?> /> Quote Link to comment https://forums.phpfreaks.com/topic/267380-imge-photo-change-name-on-thumbnail-creation/#findComment-1371195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.