It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
已关闭8年。
我只是上传:
$ path =“uploads/”;
如何为该功能添加imagejpeg?我想始终以JPG格式保存图像。
已关闭8年。
我只是上传:
$ path =“uploads/”;
$actual_image_name = time().$session_id.".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
move_uploaded_file($tmp, $path.$actual_image_name);
如何为该功能添加imagejpeg?我想始终以JPG格式保存图像。
最佳答案
试试这个:
<?php
$path = "uploads/";
$img = $_FILES['photoimg']['tmp_name'];
$dst = $path . $_FILES['photoimg']['name'];
if (($img_info = getimagesize($img)) === FALSE)
die("Image not found or not an image");
$width = $img_info[0];
$height = $img_info[1];
switch ($img_info[2]) {
case IMAGETYPE_GIF : $src = imagecreatefromgif($img); break;
case IMAGETYPE_JPEG : $src = imagecreatefromjpeg($img); break;
case IMAGETYPE_PNG : $src = imagecreatefrompng($img); break;
default : die("Unknown filetype");
}
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $width, $height, $width, $height);
imagejpeg($tmp, $dst.".jpg");
?>
关于php - 如何将上传的图像始终转换为JPG格式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14550299/
10-11 03:06