使用verot class.upload.php在上载时调整图像大小
我想在web verot class.upload.php上找到的上传图片上调整图片大小 但不幸的是,它不与我的工作,没有上传,没有调整。。 所以我的问题是这个api是否需要某种安装, 因为我只将class.upload.php上传到了我的服务器 我的函数是这样的使用verot class.upload.php在上载时调整图像大小,php,file-upload,Php,File Upload,我想在web verot class.upload.php上找到的上传图片上调整图片大小 但不幸的是,它不与我的工作,没有上传,没有调整。。 所以我的问题是这个api是否需要某种安装, 因为我只将class.upload.php上传到了我的服务器 我的函数是这样的 public function myImageR() { $foo = new Upload($_FILES['img']); if ($foo->uploade
public function myImageR()
{
$foo = new Upload($_FILES['img']);
if ($foo->uploaded) {
// save uploaded image with no changes
$foo->Process('/public/images/aa/');
if ($foo->processed) {
$a = true;
} else {
$a = false;
}
// save uploaded image with a new name
$foo->file_new_name_body = 'foo';
$foo->Process('/public/images/aa/');
if ($foo->processed) {
$a = true;
} else {
$a = false;
}
// save uploaded image with a new name,
// resized to 100px wide
$foo->file_new_name_body = 'image_resized';
$foo->image_resize = true;
$foo->image_convert = gif;
$foo->image_x = 100;
$foo->image_ratio_y = true;
$foo->Process('/public/images/aa/');
if ($foo->processed) {
$a = true;
$foo->Clean();
} else {
$a = false;
}
}
}
但它根本不起作用我正在使用xammp在本地主机上工作你需要安装GD库。。。例如,如果您使用的是ubuntu:
sudo apt-get install php5-gd
然后重新启动Apache
sudo /etc/init.d/apache2 restart
不管怎样,我用这个来调整图像大小我用这个:
要上载:
$uploaded_filename = '/www/html/picts/yourfoto.jpg';
if(isset($_FILES['your_files_field_name'])){
if (move_uploaded_file($_FILES['your_files_field_name']['tmp_name'], $uploaded_filename)) {
chmod($uploaded_filename, 0755);
return $nome; // OK
} else {
return "ERROR";
}
}
要调整大小,请执行以下操作:
<?php
$w = 40; // set width
$h = 40; // set height
$path = './'; // path
$image_file = (string) filter_input(INPUT_GET, 'img');
$image_path = $path . $image_file;
$img = null;
$ext = @strtolower(end(explode('.', $image_path)));
if ($ext == 'jpeg') {
$img = imagecreatefromjpeg($image_path);
} else if ($ext == 'jpg') {
$img = imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = imagecreatefrompng($image_path);
} elseif ($ext == 'gif') {
$img = imagecreatefromgif($image_path);
} elseif ($ext == 'bmp') {
$img = imagecreatefromwbmp($image_path);
} else {
exit("File type not found: " . $ext);
}
if ($img) {
$width = imagesx($img);
$height = imagesy($img);
$scale = min($w / $width, $h / $height);
if ($scale < 1) {
$new_width = floor($scale * $width);
$new_height = floor($scale * $height);
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
}
if (!$img) {
$img = imagecreate($w, $h);
imagecolorallocate($img, 204, 204, 204);
$c = imagecolorallocate($img, 153, 153, 153);
$c1 = imagecolorallocate($img, 0, 0, 0);
imageline($img, 0, 0, $w, $h, $c);
imageline($img, $w, 0, 0, $h, $c);
imagestring($img, 2, 12, 55, 'IMAGE ERROR', $c1);
}
header('Content-type: ' . 'image/png');
imagejpeg($img);
我希望这有帮助 它说它需要GD库,所以您需要检查您的
phpinfo()
以检查GD是否已启用。是的,它已启用,但仍然不起作用。另外,请检查upload\u max\u filesize
&post\u max\u size
在您的phpinfo()
中,这在某些情况下也会导致问题。还要检查错误日志,看看它是否产生了任何错误?谢谢Allan,你知道像hostgator这样的网站托管服务器是否可用吗?因为我愿意在那里托管我的网站,并安装了这个库??我使用的或任何VPS。如果我的回答能解决你的问题,如果你接受我的回答,我会很高兴的。
$file = '/www/html/picts/yourfoto.jpg';
$save = imagejpeg($img, $file); // save the file