我正在创建一个组件,用户创建一个新图像,还有一个上传按钮和一个名称输入,图像的所有基本图库字段..
但是我遇到了两个问题,一个是如何编写以下代码,以便它导出一个图像b / w,另一个颜色缩放到amax宽度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();
}
最后,我将如何管理这个?它将图像名称保存在数据库中,但是一旦我返回到这个项目,它就会有一个上传字段,在这里显示图像名称或显示删除功能的实际图像并重新上载...
我是否正确地对待这个问题?...任何帮助都非常感谢......谢谢:)
答案 0 :(得分:0)
您必须从上传的原始文件中创建2个资源,转换每个资源并保存在单独的文件中。例如,我使用JImage
包(注意没有limitcolors过滤器可用)
$image_one = new JImage($filepath);
$image_one
->filter('grayscale')
->toFile($path_one, IMAGETYPE_JPEG, array('quality' => 60));
$image_two = new JImage($filePath);
$image_two
->filter('limitcolors', array('limit' => 160))
->toFile($path_two, IMAGETYPE_GIF);
取决于原因,为什么要实现功能以及上传图像与其他对象/事件的关系。
如果上传的图像用于用户个人资料,则应将用户ID与图像位置一起存储在数据库中。下次检查当前用户是否有与他/她的帐户相关的任何图像并显示。