我正在使用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
答案 0 :(得分:4)
您需要使用ob_start捕获缓冲区,例如:
ob_start();
imagejpeg($tmp_img);
$i = ob_get_clean();
$ i是你的图片blob
答案 1 :(得分: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);
如果您有任何其他问题,请告诉我