How to Compress Image Size on Upload in Php -
i beginner , have been trying reduce image size on upload failing results. please me. here php code
<?php if (isset($_post['update'])){ header('location:index2.php'); $upload_image = $_files["image"][ "name" ]; $folder = "images/"; move_uploaded_file($_files["image"]["tmp_name"], "$folder".$_files["image"]["name"]); $file = 'images/'.$_files["image"]["name"]; $uploadimage = $folder.$_files["image"]["name"]; $newname = $_files["image"]["name"]; $random = substr(number_format(time() * rand(),0,'',''),0,10); $resize_image = $folder.$newname.$random; $actual_image = $folder.$newname; list( $width,$height ) = getimagesize( $uploadimage ); $newwidth = 600; $newheight = 600; $thumb = imagecreatetruecolor( $newwidth, $newheight ); $source = imagecreatefromjpeg($actual_image); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg( $thumb, $resize_image, 60 ); $out_image=addslashes(file_get_contents($resize_image)); $userid = $_session['id']; $date = $_post['date']; $data = mysqli_query($db, "select `image` `posts` id = '$userid' "); $sql = "insert posts (userid, image, date) values ('$userid', '$image', '$date')"; mysqli_query($db, $sql); } ?>
if use code getting image rotated , image not decreasing.
Comments
Post a Comment