我目前正在创建一个组件,其中用户创建一个新图像,并且有一个上传按钮和一个名称输入,图像的所有基本图库字段..
但是我遇到了两个问题,一个是我将如何编写以下代码,以便它导出一个黑白图像,另一种颜色缩放到最大宽度 160,这是我的代码:
function save(){
if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
$input=JFactory::getApplication()->input;
$input->get('jform', NULL, NULL);
$file = JRequest::getVar('jform', null, 'files', 'array');
$data = JRequest::getVar( 'jform', null, 'post', 'array' );
$path = JPATH_ROOT;
//
//
// Make the file name safe.
jimport('joomla.filesystem.file');
$file['name']['logo'] = JFile::makeSafe($file['name']['logo']);
// Move the uploaded file into a permanent location.
if (isset($file['name']['logo'])) {
// Make sure that the full file path is safe.
$filepath = JPath::clean($path. DS ."images". DS ."associations". DS . strtolower($file['name']['logo']));
// Move the uploaded file.
JFile::upload( $file['tmp_name']['logo'], $filepath );
$data['logo'] = strtolower( $file['name']['logo'] );
//convert image
$image = $filepath;
$im = new Imagick();
$im->pingImage($image);
$im->readImage( $image );
$im->setImageResolution(72,72);
$im->resampleImage(72,72,imagick::FILTER_UNDEFINED,1);
$im->scaleImage(160,0);
$im->setImageFormat('jpeg');
$im->setImageCompression(imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality(60);
$im->modulateImage(100, 0, 100);
$im->writeImage($image);
$im->destroy();
}
$input->post->set('jform',$data);
return parent::save();
}
最后,我将如何管理这个?它将图像名称保存在数据库中,但是一旦我返回此项目,它就只有一个上传字段,在该字段中显示图像名称或带有删除功能并重新上传的实际图像将非常有用...
我在这件事上走对了吗?...非常感谢您的帮助...谢谢:)