[英]CodeIgniter Resize Image function is not working
我在這段代碼中有問題。 這段代碼在我的本地Windows系統上運行。 但是相同的代碼無法在在線服務器上運行。 我有一個功能,可以根據參數將大圖像轉換為小尺寸圖像。 該功能的代碼如下。
public function do_resize($source_file, $target_folder, $height = 128, $width = 128){
$filename = $source_file;
$temp_data = explode('/',$filename);
$new_filename = end($temp_data);
$temp_data = explode('.', $new_filename);
$ext = end($temp_data);
$new_filename = $temp_data[0] . $width .'-'. $height .'.'. $ext;
$source_path = $filename;
$folder_path = '';
$temp_folder = explode('/',$target_folder);
foreach ($temp_folder as $folder) {
$folder_path .=$folder . '/';
if (!file_exists($folder_path)) {
mkdir($folder_path);
}
}
$target_path = $target_folder;
if (file_exists($source_file)) //file_exists of a url returns false.It should be real file path
{
return $folder_path . $new_filename;
}
if(isset($config_manip)){
unset($config_manip);
}
$config_manip = array(
'image_library' => 'gd2',
'source_image' => $source_path,
'maintain_ratio' => FALSE,
'new_image' => $target_path,
'create_thumb' => TRUE,
'thumb_marker' => $width . '-'. $height,
'width' => $width,
'height' => $height
);
$CI =& get_instance();
$CI->load->library('image_lib');
$CI->image_lib->initialize($config_manip);
if (!$CI->image_lib->resize()) {
echo $CI->image_lib->display_errors();
echo "<br>";
echo $config_manip['source_image'];
}
// clear //
$CI->image_lib->clear();
return $folder_path . $new_filename;
}
我這樣稱呼這個功能。
$name = $this->imageresize->do_resize($brand['logo'], $target_folder, 50, 50);
然后,輸入參數$brand['logo']
具有此值“ uploads / images / system / placeholder.png”,參數$target_folder
具有此值“ uploads / images / cache / brands / brand-logo”。 我沒有從此代碼中得到任何錯誤。 但是它也沒有調整圖像的大小。 我還將目錄的權限設置為777。
任何人對此都有一些解決方案。 謝謝
更改:
if (file_exists($source_file)) //file_exists of a url returns false.It should be real file path
{
return $folder_path . $new_filename;
}
上
if (file_exists($folder_path . $new_filename)) //file_exists of a url returns false.It should be real file path
{
return $folder_path . $new_filename;
}
和$ config_manip:
'new_image' => $target_path,
上
'new_image' => $folder_path . $new_filename,
:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.