水印和缩略图-Codeigniter
我正在编写一个脚本,创建一个缩略图,然后将水印原始图像,但该脚本只创建缩略图并跳过水印水印和缩略图-Codeigniter,codeigniter,Codeigniter,我正在编写一个脚本,创建一个缩略图,然后将水印原始图像,但该脚本只创建缩略图并跳过水印 $image = $data['json']->{'file_name'}; $data['account'] = $account; $this->_insertintodb($account, $image); //Settings to create thumbnail $config['source_image'] = $data['json']->{'
$image = $data['json']->{'file_name'};
$data['account'] = $account;
$this->_insertintodb($account, $image);
//Settings to create thumbnail
$config['source_image'] = $data['json']->{'file_path'};
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 125;
$config['height'] = 125;
$this->image_lib->initialize($config);
if($this->image_lib->resize()) {
$prep_thumb = explode('.', $image);
$thumb = $prep_thumb[0] . '_thumb.' . $prep_thumb[1];
$this->_moveimage($thumb, $account, TRUE);
}
$this->image_lib->clear();
//Settings to create watermark overlay
$config = array();
$config['source_image'] = $data['json']->{'file_path'};
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = getcwd() . '/design/overlay_watermark_transparent.png';
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
$this->image_lib->initialize($config);
if(!$this->image_lib->watermark()){
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
有没有办法解释为什么不能正常工作?您是否有所需的依赖项?发件人: 注意:水印仅在使用GD/GD2库时可用。此外,即使支持其他库,脚本也需要GD来计算图像属性。但是,将使用指定的库执行图像处理
看起来您需要安装GD,然后将其作为codeigniter图像处理库包含。您是否具有所需的依赖项?发件人: 注意:水印仅在使用GD/GD2库时可用。此外,即使支持其他库,脚本也需要GD来计算图像属性。但是,将使用指定的库执行图像处理
看起来您需要安装GD,然后将其包括在codeigniter图像处理库中。如果水印不起作用,并且您具有所需的依赖项,您应该在此处获得错误消息:
if(!$this->image_lib->watermark()){
echo $this->image_lib->display_errors();
}
这些错误可能比我们的帮助更大,或者在您向我们提供这些错误后,我们可以为您提供更多帮助。如果水印不起作用,并且您具有所需的依赖关系,您应该在此处获得错误消息:
if(!$this->image_lib->watermark()){
echo $this->image_lib->display_errors();
}
这些错误可能比我们的帮助更大,或者在您向我们提供这些错误后,我们可以为您提供更多帮助。这对我来说很有用:
/**
* public function wmimg_thumb($source_image)
*
* Creating water marked - thumb
*
* @param string $source_image : The remaining path to the source image, after FCPATH.
*
*/
function wmimg_thumb($source_image)
{
if (!file_exists($source_image))
{
return "$source_image not exists!";
}
$this->load->library('image_lib');
$config['maintain_ratio'] = TRUE;
$config['width'] = 145;
$config['height'] = 120;
$config['image_library'] = 'gd2';
$config['source_image'] = FCPATH . $source_image;
$config['create_thumb'] = TRUE;
$this->image_lib->initialize($config);
if ($this->image_lib->resize())
{
$this->image_lib->clear();
// if thumb is created, calculating the name of thumb.
$thumb_image = str_replace('.', '_thumb.', $source_image);
$img_config['wm_type'] = 'overlay';
$img_config['wm_overlay_path'] = FCPATH . '/assets/watermark.png';
$img_config['wm_x_transp'] = 20;
$img_config['wm_y_transp'] = 10;
$img_config['wm_opacity'] = 50;
$img_config['wm_vrt_alignment'] = 'bottom';
$img_config['wm_hor_alignment'] = 'center';
$img_config['source_image'] = FCPATH . $thumb_image;
$this->image_lib->initialize($img_config);
$this->image_lib->watermark();
}
if (file_exists(FCPATH . $thumb_image))
{
// Up to here, there is 2 images, $source_image_thumb.extension and $source_image_thumb_thumb.extension.
// Deleting the 1st one, which has no watermarking. And renaming the 2nd one, which will be watermarked.
unlink($thumb_image);
$wm_thumbname = str_replace('.', '_thumb.', $thumb_image);
rename(FCPATH . $wm_thumbname, FCPATH . $thumb_image);
}
}
这是为我工作的:
/**
* public function wmimg_thumb($source_image)
*
* Creating water marked - thumb
*
* @param string $source_image : The remaining path to the source image, after FCPATH.
*
*/
function wmimg_thumb($source_image)
{
if (!file_exists($source_image))
{
return "$source_image not exists!";
}
$this->load->library('image_lib');
$config['maintain_ratio'] = TRUE;
$config['width'] = 145;
$config['height'] = 120;
$config['image_library'] = 'gd2';
$config['source_image'] = FCPATH . $source_image;
$config['create_thumb'] = TRUE;
$this->image_lib->initialize($config);
if ($this->image_lib->resize())
{
$this->image_lib->clear();
// if thumb is created, calculating the name of thumb.
$thumb_image = str_replace('.', '_thumb.', $source_image);
$img_config['wm_type'] = 'overlay';
$img_config['wm_overlay_path'] = FCPATH . '/assets/watermark.png';
$img_config['wm_x_transp'] = 20;
$img_config['wm_y_transp'] = 10;
$img_config['wm_opacity'] = 50;
$img_config['wm_vrt_alignment'] = 'bottom';
$img_config['wm_hor_alignment'] = 'center';
$img_config['source_image'] = FCPATH . $thumb_image;
$this->image_lib->initialize($img_config);
$this->image_lib->watermark();
}
if (file_exists(FCPATH . $thumb_image))
{
// Up to here, there is 2 images, $source_image_thumb.extension and $source_image_thumb_thumb.extension.
// Deleting the 1st one, which has no watermarking. And renaming the 2nd one, which will be watermarked.
unlink($thumb_image);
$wm_thumbname = str_replace('.', '_thumb.', $thumb_image);
rename(FCPATH . $wm_thumbname, FCPATH . $thumb_image);
}
}
如果你单独做这两件事,它是有效的,但是当你试图一起做的时候,它不起作用。我不太明白你说的是什么。你能澄清一下吗?如果你自己运行水印功能,它就可以工作。如果您自己运行缩略图功能,它就会工作。但是如果你把它们一起运行,就不会了。试着把水印的代码放在缩略图之前。如果这是一个依赖性问题,这可能会解决。如果你单独做其中一个,它会起作用,但当你试图一起做时,它不会起作用。我不太明白你说的是什么。你能澄清一下吗?如果你自己运行水印功能,它就可以工作。如果您自己运行缩略图功能,它就会工作。但是如果你把它们一起运行,就不会了。试着把水印的代码放在缩略图之前。如果这是一个依赖性问题,这可能会解决它。