$true_array_image = CommonUtils::to_pdf_image_handle($image_array,$max_pt,'/saved_attachments/',$to_pdf_save_dir,$the_id,$postfix_str); $status_code = CommonUtils::generate_pdf($true_array_image,'/saved_attachments/',$to_pdf_save_dir,$the_id, $postfix_str,$binary_file_name,$max_pt['width'],$max_pt['height'],1);
等比例计算所有图片取大小
static function to_pdf_image_handle($image_array,&$max_pt,$sub_path,$save_file_name_type,$the_id,$postfix_str){ $max_pt["width"] = "0"; $max_pt["height"] = "0"; $true_array_image = array(); foreach($image_array as $k => $v){ $img_info = getimagesize($v); $imgtype = substr($v,strrpos($v,'.')+1); $mime =str_replace('jpeg','jpg', str_replace('image/','',$img_info['mime'])); switch ($save_file_name_type){ case IMAGE_TO_PDF_GENERATE_SAVE_TYPE_FOR_HANDOUT: $binary_identifier_str = "courseMaterials"; break; } $file_name = . (substr($v, strlen(HQ_SC_HANDOUT), strlen($v) - strlen(HQ_SC_HANDOUT))); if($imgtype != $mime){ $file_subdirectory = RESOURCE_PATH . $sub_path . $binary_identifier_str. "_" . ($the_id%100) . "/sub_". (($the_id/100)%100) . "/"; $imgurl_new = $file_subdirectory.$k.".".$mime; if(!is_dir($file_subdirectory)){ if (!mkdir($file_subdirectory, 0777, true)) { return ERR_BINARY_FILE_SAVE; } } $topng = copy($file_name,$imgurl_new); if ($topng){ $file_name = $imgurl_new; } } if (!file_exists($file_name)){ continue; } $true_array_image[] = $file_name; if ($img_info[0] > $max_pt["width"]){ $max_pt["width"] = $img_info[0]; } if ($img_info[1] > $max_pt["height"]){ $max_pt["height"] = $img_info[1]; } } $max_pt['width'] = $max_pt["width"] /4 *3 + 40; $max_pt["height"] = $max_pt["height"] /4 *3 + 40; return $true_array_image; }
生成PDF
static function generate_pdf($for_image,$sub_path,$save_file_name_type,$the_id,$postfix_str,&$binary_file_name,$width,$height,$is_delete=0){ define('FPDF_FONTPATH','/data/HQ/SC_Educations/hq_htdocs/HQ_Educations/library/FPDF/font/'); //定义font 文件夹所在路径 $pdf = new FPDF('L', 'pt', [$width,$height]); //创建新的FPDF 对象,竖向放纸,单位为毫米,纸张大小A4 $pdf->SetFont('Courier','I',20); //设置字体样式 //转成数组 switch ($save_file_name_type){ case IMAGE_TO_PDF_GENERATE_SAVE_TYPE_FOR_HANDOUT: $binary_identifier_str = "courseMaterials"; break; } $file_subdirectory = RESOURCE_PATH . $sub_path . $binary_identifier_str. "_" . ($the_id%100) . "/sub_". (($the_id/100)%100) . "/"; foreach($for_image as $k => $v){ $pdf->AddPage(); //增加一页 $pdf->Image($v,20,20,0,0); //增加一张图片,文件名为sight.jpg } if (!file_exists($file_subdirectory)){ if (!mkdir($file_subdirectory, 0777, true)) { return ERR_BINARY_FILE_SAVE; } } //扫描目录获取相关文件 if (is_dir($file_subdirectory) && $is_delete){ $handles = scandir($file_subdirectory); $postfix_first = $the_id."_".explode('_',$postfix_str)[0]; foreach ($handles as $handle){ if($postfix_first == substr($handle,0,strlen($postfix_first))){ @unlink($file_subdirectory.$handle); } if (substr(strrchr($handle, '.'), 1) == "png"){ @unlink($file_subdirectory.$handle); } } } $binary_file_name = $file_subdirectory .$the_id. "_". $postfix_str. ".pdf"; $pdf->Output($binary_file_name,'F'); $binary_file_name = substr($binary_file_name, strlen(RESOURCE_PATH), strlen($binary_file_name) - strlen(RESOURCE_PATH)); return SC_SUCCESS; }
© 版权声明
本站网络名称:
乐商网络
本站永久网址:
https://ishoud.com
网站侵权说明:
本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长QQ810066660删除处理。
1 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
2 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
3 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
1 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
2 本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
3 本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
THE END
暂无评论内容