4

我正在使用 Microsoft Azure 云,需要在那里上传图像。它的类上传方法 putBlob() 和 putBlobData() 需要数据本身(不是资源)或目录字符串作为参数,在图像实际写入 Blob 之前,这些方法都不可用。

$fp = fopen($tmp_name, 'r');
$data = fread($fp, filesize($tmp_name));
fclose($fp);

//Setup watermark destination
$new_watermarked_image_name = "watermark.jpg";

// Create image resources
$image = imagecreatefromstring($data); 
$watermark = imagecreatefrompng('images/watermark_large.png');
$copyright = imagecreatefrompng('images/copyright.png');

// Merge image resource s
$image = overlay_watermark_full_size($image, $watermark);  
$image = overlay_watermark_lower_right($image, $copyright);
imagejpeg($image, $new_watermarked_image_name, 100);

//put original image
$AzureStorageBlob->putBlob("uploads", "name", $tmp_name);
//put watermarked image
$AzureStorageBlob->putBlobData("uploads", "name", ?); // ? needs to be data
4

2 回答 2

5

您需要使用 ob_start 捕获缓冲区,例如:

ob_start();
imagejpeg($tmp_img);
$i = ob_get_clean(); 

$i 是你的图像块

于 2012-06-10T17:12:29.777 回答
0

通过使用最新的 SDK for PHP,您只需传递图像流即可:

$image_stream = fopen($tmp_name, 'r');
// Check README.md of how to create $blobRestProxy
$blobRestProxy->createBlockBlob('container_name', 'my_image', $image_stream);

如果您还有其他问题,请告诉我

于 2012-06-10T17:45:52.663 回答