我想知道是否可以通过这样的链接从php生成器添加图像?parse/BarGen/generator.php?text=760000322300000939115260
$gdImage = imagecreatefromjpeg('uploads/simple.jpg');
// Add a drawing to the worksheetecho date('H:i:s') . " Add a drawing to the worksheet'n";
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('C1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
来源:https://phpexcel.codeplex.com/
解决方案
function createImageFromFile($filename, $use_include_path = false, $context = null, &$info = null)
{
// try to detect image informations -> info is false if image was not readable or is no php supported image format (a check for "is_readable" or fileextension is no longer needed)
$info = array("image"=>getimagesize($filename));
$info["image"] = getimagesize($filename);
if($info["image"] === false) throw new InvalidArgumentException("'"".$filename."'" is not readable or no php supported format");
else
{
// fetches fileconten from url and creates an image ressource by string data
// if file is not readable or not supportet by imagecreate FALSE will be returnes as $imageRes
$imageRes = imagecreatefromstring(file_get_contents($filename, $use_include_path, $context));
// export $http_response_header to have this info outside of this function
if(isset($http_response_header)) $info["http"] = $http_response_header;
return $imageRes;
}
}
$gdImage = createImageFromFile('http://127.0.0.1:1234/dynexep/BarGen/generator.php?text=760000322300000939115260');
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('C1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());