我有一个脚本将图像文件上传到rackspace容器,之后我想要发生
麻烦是我不确定如何将重新采样的图像放入内存并上传到rackspace容器。这是代码。
$objectStoreService = $client->objectStoreService(null, 'IAD');
$container = $objectStoreService->getContainer(IMAGE_CONTAINER_NAME);
$fileData = fopen($_FILES['file-0']['tmp_name'], 'r');
$uniqid = uniqid();
$new_file_path = $uniqid."/".$_FILES['file-0']['name'];
$sm_file_path = $uniqid . "/" . 'sm_' .$_FILES['file-0']['name'];
// Upload filepath to database
$user->upload_profile_pic($new_file_path, $sm_file_path);
$result = $container->uploadObject($new_file_path, $fileData);
$new_file_path = IMAGE_CONTAINER_LINK."/".$new_file_path;
// Make Thumbnail of original image
$percent = 0.5; // percentage of resize
// Image to be changed.
$original_image = imagecreatefromjpeg($new_file_path);
list($width, $height) = getimagesize($new_file_path);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Temporary blank image in memory of height/width
$tmp_image = imagecreatetruecolor($new_width, $new_height);
// Copies the source image and copies into it the blank image and resamples it.
imagecopyresampled($tmp_image, $original_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Save the image in memory
imagejpeg($tmp_image, NULL, 100);
// read the file
// Not sure how to put image in memory to rackspace cloud.
$fileData = fopen($tmp_image, 'r');
$tmp_image = imagecreatefromstring(file_get_contents($new_file_path));
$fileData = fopen($tmp_image, 'r');
$result = $container->uploadObject($sm_file_path, $fileData);
$response = array('image_path' => $new_file_path);
header('HTTP/1.1 201 Created');
echo json_encode($response);