0
내 데이터베이스에 업로드 할 때 내 이미지의 크기를 줄이려고합니다.하지만 문제는 업로드 할 때 크기가 동일하다는 것입니다. 필자는 어떤 도움 아래에있는 내 코드 감사입니다 accepted.thank 부착하면업로드 중 PHP 이미지 크기 줄이기
<?php
include ('connection.php');
$status="<div></div>";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if($_FILES["photo_upload"]["size"]!=0){
require 'image_compressor.php';
$image_name = addslashes($_FILES['photo_upload']['name']);
$date = date("d-m-Y");
$image = addslashes(file_get_contents($_FILES['photo_upload']['tmp_name']));
$image=compress($image,$image,75);
$insert = "INSERT INTO photos (photo_image,date_uploaded,image_name) VALUES ('" .$image. "','" .$date. "','" .$image_name. "')";
$result = mysql_query($insert) or die(mysql_error());
if($result==1){
$status='<div class="alert alert-success"><a href="#" class="close" data-dismiss="alert">×</a>
<strong>Success!</strong> '.$image_name.' has been uploaded successfully.
</div>';}
else{
$status='
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Error!</strong> Please attach an image to upload.
</div>';}
unset($_FILES);}
else {
$status='
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert">×</a>
<strong>Error!</strong> Please attach an image to upload.
</div>';
}
}
?>
당신은 품질 작업 대신 새로운 폭과 높이 PHP 함수 ImageCopyResampled()
을 찾아 할 수 있습니다
<?php
function compress($source, $destination, $quality) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg')
$image = imagecreatefromjpeg($source);
elseif ($info['mime'] == 'image/gif')
$image = imagecreatefromgif($source);
elseif ($info['mime'] == 'image/png')
$image = imagecreatefrompng($source);
imagejpeg($image, $destination, $quality);
return $destination;
}