Mateobus Posted August 3, 2007 Share Posted August 3, 2007 Hey all, I am trying to implement a captcha on my website. Rather than creating the image on the fly, I would like to have a database of the captcha codes, and a thousand or so associated images. I was wondering if anyone knew how to save an image to a directory on the server, after it has been created with the imagecreatefrompng or imagecreatefromjpg function. Here is the code i found from a tutorial <?php /* Now for the GD stuff, for ease of use lets create the image from a background image. */ $captcha = imagecreatefrompng("./captcha.png"); /* Lets set the colours, the colour $line is used to generate lines. Using a blue misty colours. The colour codes are in RGB */ $black = imagecolorallocate($captcha, 0, 0, 0); $line = imagecolorallocate($captcha,233,239,239); /* Now to make it a little bit harder for any bots to break, assuming they can break it so far. Lets add some lines in (static lines) to attempt to make the bots life a little harder */ imageline($captcha,0,0,39,29,$line); imageline($captcha,40,0,64,29,$line); ?> so, i was planning on putting that in a loop and saving the images in a folder. Maybe not the most secure way, but its the most efficient. Does anyone know how to move that file to a non-temporary directory on the server? Link to comment https://forums.phpfreaks.com/topic/63140-save-image-from-imagecreatefromjpg/ Share on other sites More sharing options...
bibby Posted August 3, 2007 Share Posted August 3, 2007 Mateobus, The write out function would be imagepng() . http://us2.php.net/manual/en/function.imagepng.php So right where you've left off (or in your loop) ... // path to save, dir must be 777 , you are web-user not "you" $captcha_path = '/home/you/www/project/path/captcha/'. //save the file imagepng($captcha , $captcha_path.'filename.png'); imagepng() also be used with headers (see php.net examples) to send an image like this.. <img src="captcha.php"> , but there can be no other output. If you do decide to premake images (and I don't think that you should) , get friendly also with opendir() , readdir() , and the holy file_exists() . Link to comment https://forums.phpfreaks.com/topic/63140-save-image-from-imagecreatefromjpg/#findComment-314666 Share on other sites More sharing options...
Mateobus Posted August 3, 2007 Author Share Posted August 3, 2007 Great, thanks for the help. I was wondering why you would not suggest saving the images first? Link to comment https://forums.phpfreaks.com/topic/63140-save-image-from-imagecreatefromjpg/#findComment-314993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.