PhpSyntaxerror Posted May 5, 2013 Share Posted May 5, 2013 (edited) Hi guys ive been stuck all day since yesterday ive been trying figure out how to integrate water marking to existing upload class ive had no luck yet ive proberly tried about 30 water marking trying to integrate them but all failed could anyone show me a way to intergrate water marking with this upload, im fairly new to php is still learning sorry if im seen noobish <?php /* ** This class contains the method to upload a file */ class Upload { private $fileName; // name of the file from the upload form private $fileTypes = array(); // array of valid file types for upload private $folderPath; // folder where uploaded files will be moved public $msg; // messages generated from this class public function __construct($fileName, $fileTypes, $folderPath) { $this->fileName = $fileName; $this->fileTypes = $fileTypes; $this->folderPath = $folderPath; } public function isUploaded() // this function will contain the statements to process file upload // and returns the name of the file upon successful upload // or returns false otherwise. It also sets the upload message ($this->msg) { $this->msg = ''; // check if the name of the file uploaded is not available if (!$_FILES[$this->fileName]['name']) { $this->msg .= 'File name not available'; return false; } // test for error in uploading if ($_FILES[$this->fileName]['error']) { switch ($_FILES[$this->fileName]['error']) { case 1: $this->msg .= 'File exceeds PHP\'s maximum upload size<br />'; return false; case 2: $this->msg .= 'File exceeds maximum upload file set in the form<br />'; return false; case 3: $this->msg .= 'File partially uploaded<br />'; return false; case 4: $this->msg .= 'No file uploaded<br />'; return false; } } // check if file type is invalid $type = $_FILES[$this->fileName]['type']; // get the type of the uploaded file if (!in_array($type, $this->fileTypes)) { $this->msg .= 'Wrong file type<br />'; return false; } // check if file did not reach the server (temp location) if (!is_uploaded_file($_FILES[$this->fileName]['tmp_name'])) { $this->msg .= 'File did not reach temporary location on the server<br />'; return false; } $fleName = $_FILES[$this->fileName]['name']; $flePath = $this->folderPath ? $this->folderPath . '/' . $fleName : $fleName; // test if a file with the same name exist, and rename if it does if (file_exists($flePath)) { $newName = uniqid('LD') . $fleName; $this->msg .= 'File ' . $fleName . ' already exists, renamed to ' . $newName . '<br />'; $flePath = $this->folderPath ? $this->folderPath . '/' . $newName : $newName; } // move file from temporary location to the path specified // and test if it's not successful if (!move_uploaded_file($_FILES[$this->fileName]['tmp_name'], $flePath)) { $this->msg .= 'Error in moving file to specified location<br />'; return false; } // check if file does not exist on the destination folder if (!file_exists($flePath)) { $this->msg .= 'File did not reach destination folder<br />'; return false; } $this->msg .= 'File ' . $_FILES[$this->fileName]['name'] . ' uploaded successfully<br />'; return $flePath; } } ?> Edited May 5, 2013 by ignace Added code tags Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 5, 2013 Share Posted May 5, 2013 You need to show us what you tried and what didn't work. Our rules specifically state that we are not here to do your homework. If you can't do the coursework, you deserve to fail. If you can make an effort and get help based on the work you've done, that's fine IMO. Quote Link to comment Share on other sites More sharing options...
PhpSyntaxerror Posted May 5, 2013 Author Share Posted May 5, 2013 (edited) hi ive tried a couple of them but i will load up some of the ones ive save as in water marking but i seems i not too sure how to intergrate a interchangeable one from the form to the ones that people had made online >< im not sure how to fit the together into my upload class that does the watermarking. <?php //open up the images $fleName = $_FILES[$this->fileName]['name']; //get the image information $dolpInfo = getimagesize('dolphin.jpg'); $watermark = imagecreatefrompng('optimized\images\watermark.png'); $waterInfo = getimagesize('optimized\images\watermark.png'); $x = $dolpInfo[0] - $waterInfo[0] - 5; $y = $dolpInfo[1] - $waterInfo[1] - 5; //add the watermark to the image imagecopy($dolphin, $watermark, $x, $y, 0, 0, $waterInfo[0], $waterInfo[1]); //display it onscreen header('Content-Type: image/jpeg'); imagejpeg($dolphin); ?> also tried intergrating <?php // Load the stamp and the photo to apply the watermark to $im = imagecreatefromjpeg('photo.jpeg'); // First we create our stamp image manually from GD $stamp = imagecreatetruecolor(100, 70); imagefilledrectangle($stamp, 0, 0, 99, 69, 0x0000FF); imagefilledrectangle($stamp, 9, 9, 90, 60, 0xFFFFFF); $im = imagecreatefromjpeg('photo.jpeg'); imagestring($stamp, 5, 20, 20, 'libGD', 0x0000FF); imagestring($stamp, 3, 20, 40, '© 2007-9', 0x0000FF); // Set the margins for the stamp and get the height/width of the stamp image $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); // Merge the stamp onto our photo with an opacity of 50% imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50); // Save the image to file and free memory imagepng($im, 'photo_stamp.png'); imagedestroy($im); ?> and <?php function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile) { list($width, $height) = getimagesize($SourceFile); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($SourceFile); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); $black = imagecolorallocate($image_p, 0, 0, 0); $font = 'arial.ttf'; $font_size = 10; imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $WaterMarkText); if ($DestinationFile<>'') { imagejpeg ($image_p, $DestinationFile, 100); } else { header('Content-Type: image/jpeg'); imagejpeg($image_p, null, 100); }; imagedestroy($image); imagedestroy($image_p); }; ?> Edited May 5, 2013 by ignace Added code tags Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 5, 2013 Share Posted May 5, 2013 Why don't you try writing your own? You're not going to school to learn how to copy and paste are you? Quote Link to comment Share on other sites More sharing options...
PhpSyntaxerror Posted May 5, 2013 Author Share Posted May 5, 2013 ive tried a few times but the quality of the teacher that thought me was very low it was his first class and he didnt make any sense and was sometimes teaching us backwards his grammar was horrible i did not understand anything or retrain anything he had said so i learn php my self slowly Quote Link to comment Share on other sites More sharing options...
PhpSyntaxerror Posted May 5, 2013 Author Share Posted May 5, 2013 its the best of what i can with the circumstances Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 5, 2013 Share Posted May 5, 2013 It's amazing how many people come on here and complain about their teachers being horrible. Your response to a bad teacher is to basically give up? Don't schools these days have administration anymore? When I had a bad teacher I complained to the people who could actually do something about it. Anyway since you've still not posted what errors you got with what code, you're still basically asking someone to do it for you. In the future, use code tags when you post, your code is unreadable. Quote Link to comment Share on other sites More sharing options...
PhpSyntaxerror Posted May 5, 2013 Author Share Posted May 5, 2013 i did already complain to the head of department funny thing is she kept supporting him because she was the one who hired him. ive been on trying to do water mark for almost 30hrs now and its here almost 3am almost im not trying to ask anyone to do it for me im at a point where i am stuck. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 5, 2013 Share Posted May 5, 2013 Again - what part are you "stuck" on? Do you understand exactly what you're trying to do? Once you know what your goal is, find the functions that will do it, then write the code. Stop trying to use other people's code, and write your own. Quote Link to comment Share on other sites More sharing options...
PhpSyntaxerror Posted May 5, 2013 Author Share Posted May 5, 2013 im not understanding how to put if (!is_uploaded_file($_FILES[$this->fileName]['tmp_name'])) { $this->msg .= 'File did not reach temporary location on the server<br />'; return false; } $fleName = $_FILES[$this->fileName]['name']; $flePath = $this->folderPath ? $this->folderPath . '/' . $fleName : $fleName; // test if a file with the same name exist, and rename if it does if (file_exists($flePath)) { as to $fileName = $_FILES[$this->fileName]['name']; $watermark = imagecreatefrompng('optimized\images\watermark.png'); $waterInfo = getimagesize('optimized\images\watermark.png'); $x = $filename[0] - $waterInfo[0] - 5; $y = $filename[1] - $waterInfo[1] - 5; //add the watermark to the image imagecopy($filename, $watermark, $x, $y, 0, 0, $waterInfo[0], $waterInfo[1]); //display it onscreen header('Content-Type: image/jpeg'); imagejpeg($filename); im not sure something like that but when i do i just get a blank page Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 5, 2013 Share Posted May 5, 2013 Pretty sure your teacher is fine. You just have a listening problem. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 5, 2013 Share Posted May 5, 2013 basic method create gd image from original photo using imagecreatefromjpeg create second gd image from your watermark image copy from watermark image to original using imagecopymerge so you can apply transparency output original with imagejpeg(filename) destroy both gd images Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 5, 2013 Share Posted May 5, 2013 This guy taught me how to do an image upload script with his videos: http://www.youtube.com/watch?v=T0Uv3VeTMR8 That's all the help I can provide you. Quote Link to comment Share on other sites More sharing options...
kicken Posted May 5, 2013 Share Posted May 5, 2013 im not understanding how to put ... Your problem is that your trying to figure out how to combine pieces of pre-written PHP code. Instead you should just think about what process you have to go through to generate a watermarked image and then try and develop code for that. Once you know the proper process, figuring out where in your upload processing the code to do it should go should be relatively simple. Quote Link to comment 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.