如何读取图像并调整大小并将重新调整大小的图像再次上传到rackspace容器

时间:2014-03-05 10:07:27

标签: php image-resizing rackspace-cloud rackspace

我正在尝试此代码,但它无法正常工作

require('cloudfiles/cloudfiles.php');

$auth = new CF_Authentication($username, $key);
$auth->authenticate();
$conn = new CF_Connection($auth);

$container = $conn->get_container('images');
                $localfile = $_FILES['upload']['tmp_name'];
                $ext = pathinfo($_FILES["upload"]['name'], PATHINFO_EXTENSION);
                $filename = "logos/xs/test-coupons-codes." . $ext;

                 // upload file to Rackspace
                $object = $container->create_object($filename);
                $object->load_from_filename($localfile);

                $obj = $container->get_object($filename); 
                $data = $obj->read();

                $size = 150;  // new image width
                $src = imagecreatefromstring($data); 
                $width = imagesx($src);
                $height = imagesy($src);
                $aspect_ratio = $height/$width;

                if ($width <= $size) {
                  $new_w = $width;
                  $new_h = $height;
                } else {
                  $new_w = $size;
                  $new_h = abs($new_w * $aspect_ratio);
                }

                $img = imagecreatetruecolor($new_w,$new_h); 
                imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);
                imagedestroy($src);

              imagejpeg($img); //you does not want to save.. just display

              $filename1 = "logos/s/test-coupons-codes.jpg";

                 // upload file to Rackspace
                 $object = $container->create_object($filename1);
                 $object->write($img);
                 //$object->load_from_filename($img);
imagedestroy($img);

0 个答案:

没有答案