Distant_storm Posted December 3, 2007 Share Posted December 3, 2007 Ok ive made a captcha as just practice with image stuff. although I want now to be able to do the following... 1) Specify the temporary location for a upload file 2) not as much watermark the image but create image like a captcha making lines on it and some text 3) Destroy the temp image and the fully uploaded image 4) save the watermarked image. Any ideas on how id go about it . Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 4, 2007 Author Share Posted December 4, 2007 er bump Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted December 4, 2007 Share Posted December 4, 2007 You want to place your captcha type stuff on an uploaded image? Use imagecopymerge. Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 4, 2007 Author Share Posted December 4, 2007 Ok ive made upload script uploads a file to a specific folder. From that image now I want to watermark it although ive seen a watermark code which takes another image and merges it with the origonal image. I don't want to do it this way. I want to use my captcha method of actully putting text onto the image and lines. although I don't know how to go about it because ive used functions to create the captcha from scratch rather than image. like so function makeRGBColor($color,$image) { $color = str_replace('#',"",$color); $red = hexdec( substr($color,0,2) ); $green = hexdec( substr($color,2,2) ); $blue = hexdec( substr($color,4,2) ); $out = imagecolorallocate($image,$red,$green,$blue); return($out); } $font="arial.ttf"; $fontsize=18; $padding=18; $wordbox= imageftbbox($fontsize,0,$font,$target); $wordboxwidth=$wordbox[2]; $wordboxheight=$wordbox[1]; + abs($wordbox[7]); $containerwidth = $wordboxwidth + ($padding *2); $containerheight = $wordboxheight + ($padding * 2); $textx= $padding; $texty= $containerheight - $padding; $captchaimage = imagecreate($containerwidth,$containerheight); $backgroundcolor= makeRGBColor( 'EDEDED',$captchaimage); $textcolor= makeRGBColor('A8ADB4', $captchaimage); imagefttext($captchaimage,$fontsize,0,$textx,$texty,$textcolor,$font,$target); $angle= rand(-20,20); $captchaimage = imagerotate($captchaimage,$angle,$backgroundcolor); $line = makeRGBColor('FFFFFF',$captchaimage); for ($i = 0; $i < 3; $i++) { $xstart= rand (0,$containerwidth); $ystart= rand (0,$containerheight); $xend= rand (0,$containerwidth); $yend=rand (0,$containerheight); imageline($captchaimage,$xstart,$ystart,$xend,$yend,$line); } header ('content-type:image/png'); imagepng($captchaimage); Although i want this instead of on image box onto my image I then want to save that image instead of it just being destroyed. Any help would be much apreciated thanks Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted December 4, 2007 Share Posted December 4, 2007 Change this line: $captchaimage = imagecreate($containerwidth,$containerheight); to something like: $captchaimage = imagecreatefromjpg( 'uploaded_image.jpg' ); Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 4, 2007 Author Share Posted December 4, 2007 ahh and just change jpg to gif and such ? and also what if its JPEG will that matter ? Do you have any suggestions for the end stage of saving the file Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 4, 2007 Share Posted December 4, 2007 If the image you want is a jpg, use ImageCreateFromJpeg(); If the image you want is a png, use ImageCreateFromPng(); If the image you want is a gif, use ImageCreateFromGif(); Then at the end to save it. header (content-type: image/png) ImagePng($captchaimage); //paints the image in the browser ImagePng($captchaimage, "captcha.png"); //Saves it as a png file called 'captcha.png' ImageDestroy($captchaimage); //clean up the resources Hope that helps, Sam Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 4, 2007 Author Share Posted December 4, 2007 Erm i Think ibroke it ? This error Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 11392 bytes) in XXXX/XXXXX/XXXXXX/XXXXXX on line 83 What does that erorr mean ? this is my code up to now... $file_allocation= "../" . $base_url_temp . "/" . $_FILES['photofile']['name']; //watermark image function makeRGBColor($color,$image) { $color = str_replace('#',"",$color); $red = hexdec( substr($color,0,2) ); $green = hexdec( substr($color,2,2) ); $blue = hexdec( substr($color,4,2) ); $out = imagecolorallocate($image,$red,$green,$blue); return($out); } $font="arial.ttf"; $fontsize=18; $padding=18; list($width, $height, $type, $attr) = getimagesize($file_allocation); $textx= $padding; $texty= $width - $padding; $captchaimage = ImageCreateFromJpeg($file_allocation); $backgroundcolor= makeRGBColor( 'EDEDED',$captchaimage); $textcolor= makeRGBColor('A8ADB4', $captchaimage); imagefttext($captchaimage,$fontsize,0,$textx,$texty,$textcolor,$font,"Kayleigh.co.uk"); $angle= rand(-20,20); $captchaimage = imagerotate($captchaimage,$angle,$backgroundcolor); $line = makeRGBColor('FFFFFF',$captchaimage); for ($i = 0; $i < 3; $i++) { $xstart= rand (0,$width); $ystart= rand (0,$height); $xend= rand (0,$width); $yend=rand (0,$height); imageline($captchaimage,$xstart,$ystart,$xend,$yend,$line); } header ('content-type: image/png'); ImagePng($captchaimage); ImagePng($captchaimage . "../" . $base_watermark . "/captcha.png"); ImageDestroy($captchaimage); any help will be much apreciated, I have never seen that error message before is the file just too big or something? Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 5, 2007 Share Posted December 5, 2007 'Tis a bit odd, since you don't have a line 83 but there is a limit to file size, which you change in your php.ini, I think (feel free to correct me if I'm wrong). Also, you have to make sure that the image you are making it from actually is .jpg, or .jpeg in order to use ImageCreateFromJpeg(); Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 5, 2007 Author Share Posted December 5, 2007 I am pretty sure that my ini settings are still default which i believe is 8mb. I am testing image which are 726kb and they are jpg. I duno if they have to be non progressive ? I have had some results which just show a box with red x, although i keep getting this error message There is no line 83 because i haven't included all my code but i will.. <?php //image upload handel #Connect to database get file listing if ($dbc = @mysql_connect('host','user','xxxxx')) { if (@mysql_select_db('db')) { $query="SELECT * FROM table"; if ($r = mysql_query ($query)) { while ($row = mysql_fetch_array($r)) { $base_url_temp=$row['xxx']; $base_watermark=$row['xxxxx']; } } // atempt to upload file $allow_file="FALSE"; $allowed_file_types = array(1=>'image/gif',2=>'image/pjpeg',3=>'image/jpg',4=>'image/jpeg',5=>'image/JPG',6=>'image/JPEG',7=>'image/pjpg',8=>'image/png'); $total_file_types= count($allowed_file_types); for($c=1;$c < $total_file_types; $c++) { if ($allowed_file_types[$c] == $_FILES['photofile']['type']) { $allow_file="TRUE"; } } if ($_FILES['photofile']['size'] > "8388608") { $allow_file="FALSE"; } if ($allow_file == "FALSE") { exit("file was too big or wrong type" . $_FILES['photofile']['type'] . "<br>" . $_FILES['photofile']['size']); } if (move_uploaded_file ($_FILES['photofile']['tmp_name'],".." . $base_url_temp . "/" . $_FILES['photofile']['name'])) { echo "file uploaded"; } else { echo $_FILES['photofile']['error']; } $file_allocation= ".." . $base_url_temp . "/" . $_FILES['photofile']['name']; //watermark image function makeRGBColor($color,$image) { $color = str_replace('#',"",$color); $red = hexdec( substr($color,0,2) ); $green = hexdec( substr($color,2,2) ); $blue = hexdec( substr($color,4,2) ); $out = imagecolorallocate($image,$red,$green,$blue); return($out); } $font="arial.ttf"; $fontsize=18; $padding=18; list($width, $height, $type, $attr) = getimagesize($file_allocation); $textx= $padding; $texty= $width - $padding; $captchaimage = ImageCreateFromJpeg($file_allocation); $textcolor= makeRGBColor('A8ADB4', $captchaimage); imagefttext($captchaimage,$fontsize,0,$textx,$texty,$textcolor,$font,"Kayleigh.co.uk"); $line = makeRGBColor('FFFFFF',$captchaimage); for ($i = 0; $i < 3; $i++) { $xstart= rand (0,$width); $ystart= rand (0,$height); $xend= rand (0,$width); $yend=rand (0,$height); imageline($captchaimage,$xstart,$ystart,$xend,$yend,$line); } header ('content-type: image/gif'); ImagePng($captchaimage); ImagePng($captchaimage,"captcha.gif"); ImageDestroy($captchaimage); } } ?> Quote Link to comment Share on other sites More sharing options...
tippy_102 Posted December 5, 2007 Share Posted December 5, 2007 Have a look at this page: http://ca.php.net/imagecreatefromjpeg regarding memory usage, especially the resent post by dmhouse at gmail dot com. Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 5, 2007 Share Posted December 5, 2007 $file_allocation= ".." . $base_url_temp . "/" . $_FILES['photofile']['name']; $captchaimage = ImageCreateFromJpeg($file_allocation); //line 83 So at the moment the $file_allocation is (if we imagine $row['xxx']; = example, and $_FILES = file) '..example/file', why is that? Or does $row['xxx'] include a "/"? Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 5, 2007 Author Share Posted December 5, 2007 Sorry yes $row includes the / Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted December 5, 2007 Author Share Posted December 5, 2007 hmm Thanks helraizer for that link read up about it, seems to explain it pretty clear although 'fudge factor' haha what name. Think I may use the image merge instead of this method as it seems to be a little complex for its purposes Thanks again for everyones help 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.