2014-11-03 157 views
-1

我想知道是否有可能從這樣的鏈接添加圖像從一個PHP發電機? parse/BarGen/generator.php?text=760000322300000939115260PhpExcel - 從PHP生成器添加圖像?

$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/

+0

你嘗試了嗎?是**大膽**;) – 2014-11-03 18:11:26

+0

我做到了,但如此$ gdImage = imagecreatefromjpeg(),我跟着一些例子。 – Kavvson 2014-11-03 18:12:15

+0

你有沒有得到任何錯誤? – 2014-11-03 18:23:57

回答

1

解決方案

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());