我正在尝试调整大小并替换用户上传的图像,但我可以做的最多的是调整大小并将其作为另一个文件输出。我已经使用图书馆图像魔术师来调整大小。调整大小并使用PHP替换图像
如果有人能解释我如何做到这一点,而不使用库它会更好。
public function add() {
$f=Base::instance()->get('FILES');
$fext=pathinfo ($f['usrimg']['name'],PATHINFO_EXTENSION);
$this->copyFrom('POST');
$this->save();
$newName=str_pad($this->_id,5,"0").'.'.$fext;
move_uploaded_file($f['usrimg']['tmp_name'], $newName);
$this->load('id='.$this->_id);
$this->set('photo',$newName);
$this->update();
require_once('php_image_magician.php');
$magicianObj = new imageLib($newName);
$magicianObj->resizeImage(100, 200);
$magicianObj->saveImage('q.jpg', 100);
}
我建议你使用'gd'或'gd2'库。它非常完整且易于使用。 –
你可以给我一个例子,如果它的大小超过一定的大小,请确定图片的大小@AmirZojaji – thenoob
我在一个新的答案中找出它。 –