PHP - Save Image After Jrcop
hi all,
i'm trying to save an image after cropping it using jcrop (jquery plugin). i'm currently using a script i found on the internet called ImageManipulation.php (attached). its working fine, but i get a black image if i crop a gif, or png images (works great for jpg images). Code: [Select] $objImage = new ImageManipulation("../products/" . $_SESSION['image']); if ($objImage->imageok) { // get x, y, w, h from hidden inputs that are update by jcrop $objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']); $objImage->resize(150); $objImage->save("../products/" . $_SESSION['image']); } how can i fix this?? if you have a better way of using php with jcrop to save cropped images please share it thanks for the help Similar TutorialsThis resizer works fine except I would like it to save the original image AND the thumbnail. Right now its only saving the cropped thumbnail. It's seems simple enough but I've tried several different ways but can't get it to work. :( I would appreciate your help. :) define( 'DESIRED_IMAGE_WIDTH', 150 ); define( 'DESIRED_IMAGE_HEIGHT', 150 ); $source_path = $_FILES[ 'thumb' ][ 'tmp_name' ]; $timestamp = time(); $target = "image_files/".$imagename; move_uploaded_file($source, $target); // // Add file validation code here // list( $source_width, $source_height, $source_type ) = getimagesize( $source_path ); switch ( $source_type ) { case IMAGETYPE_GIF: $source_gdim = imagecreatefromgif( $source_path ); break; case IMAGETYPE_JPEG: $source_gdim = imagecreatefromjpeg( $source_path ); break; case IMAGETYPE_PNG: $source_gdim = imagecreatefrompng( $source_path ); break; } $source_aspect_ratio = $source_width / $source_height; $desired_aspect_ratio = DESIRED_IMAGE_WIDTH / DESIRED_IMAGE_HEIGHT; if ( $source_aspect_ratio > $desired_aspect_ratio ) { // // Triggered when source image is wider // $temp_height = DESIRED_IMAGE_HEIGHT; $temp_width = ( int ) ( DESIRED_IMAGE_HEIGHT * $source_aspect_ratio ); } else { // // Triggered otherwise (i.e. source image is similar or taller) // $temp_width = DESIRED_IMAGE_WIDTH; $temp_height = ( int ) ( DESIRED_IMAGE_WIDTH / $source_aspect_ratio ); } // // Resize the image into a temporary GD image // $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height ); imagecopyresampled( $temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height ); // // Copy cropped region from temporary image into the desired GD image // $x0 = ( $temp_width - DESIRED_IMAGE_WIDTH ) / 2; $y0 = ( $temp_height - DESIRED_IMAGE_HEIGHT ) / 2; $desired_gdim = imagecreatetruecolor( DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); imagecopy( $desired_gdim, $temp_gdim, 0, 0, $x0, $y0, DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); // // Render the image // Alternatively, you can save the image in file-system or database // header( 'Content-type: image/jpeg' ); imagejpeg( $desired_gdim, "image_files/" . $timestamp . $_FILES["thumb"]["name"] ); Hi I have a javascript image cropping script which is working well, I then have some php to save the new cropped image. But I can't seem to get it working 100%. When the form is posted the cropped image is not created and I get a "The connection was reset" error. If I comment out the line Code: [Select] $source=imagecreatefromjpeg($image); then I dont get the The connection was reset" error but the image is obviously still not created. Can anyone help? Code: [Select] <?php function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){ list($imagewidth, $imageheight, $imageType) = getimagesize($image); $imageType = 'image/jpeg'; $newImageWidth = ceil($width * $scale); $newImageHeight = ceil($height * $scale); $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); switch($imageType) { case "image/jpeg": case "image/jpg": $source=imagecreatefromjpeg($image); break; } imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height); switch($imageType) { case "image/jpeg": case "image/jpg": imagejpeg($newImage,$thumb_image_name,90); break; } chmod($thumb_image_name, 0777); return $thumb_image_name; } function getHeight($image) { $size = getimagesize($image); $height = $size[1]; return $height; } function getWidth($image) { $size = getimagesize($image); $width = $size[0]; return $width; } $large_image_location = $upload_path.$large_image_name.'.jpg'; $thumb_image_location = $upload_path.$thumb_image_name.'.jpg'; if (isset($_POST["upload_thumbnail"])) { $x1 = $_POST["x1"]; $y1 = $_POST["y1"]; $x2 = $_POST["x2"]; $y2 = $_POST["y2"]; $w = $_POST["w"]; $h = $_POST["h"]; $scale = $thumb_width/$w; $cropped = resizeThumbnailImage($thumb_image_location, $large_image_location,$w,$h,$x1,$y1,$scale); header("location:index.php"); exit(); } ?> Hi Guys, Please can someone here help me with a simple browse for an image from the computer and then when the form is submitted it uploads the image and then saves the image url in my DB. my form page is here http://bit.ly/gntCvD Any help will be appreciated. thanks Craig Hi all, i need little help in saving and download gif image created by using GD library. code works fine in mozilla and crome but in IE a new new page where the image is created,saved as well as dowloaded remains open and shows this"Action canceled". but the image is stored and downloaded on my system. i just want to close this page automatically when download is complete Code: [Select] <?php ob_start(); ini_set("memory_limit","180M"); $data = explode(",", $_POST['img']); $width = $_POST['wp']; $height = $_POST['ht']; $image=imagecreatetruecolor( $width ,$height ); $background = imagecolorallocate( $image ,0 , 0 , 0 ); //Copy pixels $i = 0; for($x=0; $x<=$width; $x++){ for($y=0; $y<=$height; $y++){ $int = hexdec($data[$i++]); $color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int); imagesetpixel ( $image , $x , $y , $color ); } } //Output image and clean header( "Content-type: image/gif" ); $name = rand(0,9999); $n = $name; $name = "img/".$name.".gif"; ImageGIF($image,$name,100); imagedestroy($image); $path = "http://localhost/madeup/img/"; $fullPath = $path.$n.'.gif'; if ($fd = fopen ($fullPath, "r")) { header( "Content-type: image/gif" ); header("Content-Disposition: attachment; filename=".$n); header("Cache-control: private"); while(!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } } fclose ($fd); ob_end_flush(); exit; ?> I'm trying to save images from a directory into mine. To get the image I am having to take the email from a database, split it and take whatever it is before the '@' sign and add it to "-S.jpg". I wrote the script and when I echo the variable it shows the correct thing, but when it tries to save it , it is trying to find the image as "script>-S.jpg". It looks like it is taking whatever is after the last '/' which in the variable since I am running javascript it is going to be </script> if you look at my variable $url. Here is the code below. Any help is appreciated. while($rows=mysql_fetch_array($result)){ $email=$rows['email']; $url= "<SCRIPT LANGUAGE=\"javascript\"> var url; var email = \"$email\"; function emailsplit () { var userid = email.split(\"@\"); var url = userid[0]; var imgid = \"http://my.snu.edu/images/idpictures/\" + url + \"-S.jpg\"; return url; } document.write(emailsplit()); </script> "; $img[]= 'http://my.snu.edu/images/idpictures/'.$url.'-S.jpg'; } function save_image($img,$fullpath='basename'){ if($fullpath=='basename'){ $fullpath = basename($img); } $ch = curl_init ($img); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec($ch); curl_close ($ch); if(file_exists($fullpath)){ unlink($fullpath); } $fp = fopen($fullpath,'x'); fwrite($fp, $rawdata); fclose($fp); } foreach($img as $i){ save_image($i); if(getimagesize(basename($i))){ echo '<h3 style="color: green;">Image ' . basename($i) . ' Downloaded OK</h3>'; }else{ echo '<h3 style="color: red;">Image ' . basename($i) . ' Download Failed</h3>'; } } Hi, I am tryng to use the gd functions in php to output an image of a lower quality and save it as another image: Code: [Select] header('Content-Type: image/jpeg'); $im = @imagecreatefromjpeg('SDC10424.JPG'); imagejpeg($im, null, 50);// this line lowers the image quality imagedestroy($im); but the problem is how to save it? I tried file_put_contents, but it didnt work, like fileputcontents("test.jpg", $im); How can i save image just assume that i have "test.jpg" and wish to store the image to directory "directory A" using Curl..how can i do that? thanks in adv My current project requires me to save the number of views an image (banner ad) has appeared on users website. The problem here is that the image will be appearing on several users website and i want to be able to save the number of times it has appeared on my database. I know how to do this if the image was on the same server as the database, but not when the image and database are on completely different servers. This is somewhat like analytic where it tracks the visitors to a page. Does anyone how i can accomplish this? i figured i would need to create a JavaScript code to provide to the user so they can place it on the site but how do i get that code to connect to my database? Hey guys! I have the following script to create an excel file, the thing is that I dont want to be asked if I want to open or save the file when accessing the php file...I just want the php file directly to save the excel file. Heres the code: $filename = "test.xls"; $contents = "testdata1 \ntestdata2 \ntestdata3 \n"; header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename='.$filename); echo $contents; Is there a way instead of using the header function, use something like: fopen, fwrite, fclose ? Thanks in advance! Cheers, This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=321638.0 Hi, I want to save an webpage into my server location, as simple as that. At present, I am reading the content of the file using curl, save that content into a text file, then save that text file. I assume there must be some straightforward way just to save www.example.com/file.html into my server directory as file.html. Can anyone help me on this, please? Thanks, -Abd test.php Code: [Select] <?php setcookie("test", 'tester', time()+3600*24*30 , "/", ".mystagingsite1.com"); header('Location: test2.php'); ?> test2.php Code: [Select] <?php echo '<pre>'; print_r($_COOKIE); echo '</pre>'; ?> This does not work. It's not setting the cookie at all. Is there something I am doing wrong here? I want to save files to a directory. I am using a input type="text" to let user paste directory, then they choose the file from an upload form, then press submit. So here is my script: ============== <form method="post" action="" enctype=...> <input type="text" name="textboxDir" /> <input type="file" name="uploadedFile"/> </form> So how do I now save the uploaded file via $_POST['uploadedFile'] to the text box directory: $_POST["textBoxDir"]? Any help much appreciated! I have a button that brings up my systems printer....
<button onClick="window.print()">Print this page</button>I'm trying to find a way to do the same thing but giving me the ability to save-as to my CPU. What would be nice is if I could have separate buttons to save-as a PDF and one for CSV. Each would automatically save to a file, with a comfirmation that its saved. The location would be coded in PHP for the desired format, and all the user has to do is click the button and it is placed in the appropriate folded. is this possible and easy to do across ie, firefox and chrome? Thanks for any direction. . Edited by Butterbean, 15 January 2015 - 12:09 AM. Im trying to use a cropping feature but when the image is cropped the alpha channel is lost. Anyone know where im going wrong here? if($ext == 'png') { $srcImg = imagecreatefrompng('avatars/'.$original); $newImg = imagecreatetruecolor($width, $height); imagealphablending($srcImg, true); imagesavealpha($srcImg, true); imagecopyresampled($newImg, $srcImg, 0, 0, $x1, $y1, $width, $height, $width, $height); imagepng($newImg, 'avatars/'.$user_name.'_avatar_cropped.png'); $link->query("UPDATE ".TBL_PREFIX."users SET u_avatar_cropped = '".$user_name."_avatar_cropped.png' WHERE u_username = '$user_name'") or die(print_link_error()); } good day here! I'm new in php, and i want to save diff array at the same time. is it possible? if (isset($_POST['submit'])) { $user_Id = $_POST['user_Id']; $se_Id = $_POST['se_Id']; $status = $_POST['status']; foreach ($_POST['user_Id'] as $user_Id) <-- this is working, but I want to include the other array { mysql_query("INSERT tbl_data (user_Id,se_Id,status) VALUES ('$user_Id','$se_Id,'$status'')") or die(mysql_error()); } } help me guys. $new_relation->save(); echo "after save".$requestor_profile->getId()." ".$requestee_profile->getId(); return true; }catch(PropelException $e) { echo "in die"; die($e); return false; } }//end - if (!$res) [/PHP] the echo after the save executes but when i look in my db table there is nothing???? please help??? What is the best way to capture items that someone wants to purchase when they don't have an account yet? And I prefer not using cookies.
This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=353684.0 this is the script it is supposed to get the image url and file name from the address bar and then save the image in the pics folder. it doesn't work and there are no errors, i have never used curl before so i don't know what i am doing. the $img is commented out because i don't know how to add it into the code. <?php $url = $_GET["url"]; //$img = $_GET["fileName"]; $fullpath = "/hermes/bosweb/web230/b2302/ipg.account/test_server/pics"; function save_image($url,$fullpath){ $ch = curl_init ($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec($ch); curl_close ($ch); if(file_exists($fullpath)){ unlink($fullpath); } $fp = fopen($fullpath,'x'); fwrite($fp, $rawdata); fclose($fp); } ?> this is was the end of the url looks like Code: [Select] save.php?url=http%3A%2F%2Fapi10.webresizer.com%2Fresizer%2Fdisplay.cgi%3Fsession%3DLO7WC4zoiw1z4pLFMIjK1dps3Q9HKP%26from%3Dresult.jpg%26type%3Djpg&filetype=jpg&filename=Group.jpg&filesize=39.07&width=385&height=289 |