예제 #1
0
 static function clip_pic($width, $height, $pic, $domain)
 {
     $s = new SaeStorage();
     $img = new SaeImage();
     $w = $width;
     $h = $height;
     if (!($img_data = $s->read($domain, $pic))) {
         echo $domain . "&&&&" . $pic;
         die('图片读取失败!');
     }
     $img->setData($img_data);
     //获取预设剪裁高宽比
     $x2 = $h / $w;
     if (!($image_size = $img->getImageAttr())) {
         die('获取属性失败!');
     }
     //图片实际高宽比
     $he = $image_size[1];
     $we = $image_size[0];
     $x1 = $he / $we;
     //图片实际高宽比和预设高宽比之比
     $x12 = $x1 / $x2;
     if ($x12 < 1) {
         //如果实际图片比预设值高
         if ($we > $w) {
             $img->resize($w);
         }
         //按预设宽度等比缩小
     } else {
         //如果实际图片比预设值宽
         if ($he > $h) {
             $img->resize(0, $h);
         }
         //按预设高度等比缩小
     }
     $result = $img->exec();
     if ($result == false) {
         echo "剪切失败!";
         var_dump($img->errno(), $img->errmsg());
     } else {
         return $result;
     }
 }
예제 #2
0
     exit_status('error', 'Only Image can upload!');
 }
 if ($file['size'] > 10 * 1024 * 1024) {
     exit_status('error', 'Max file size is 5MB!');
 }
 $form_data = $file['tmp_name'];
 $dumpdata = file_get_contents($form_data);
 $img = new SaeImage();
 $img->setData($dumpdata);
 $img->resize(600);
 // 等比缩放到600宽
 $new_data = $img->exec('jpg');
 // 执行处理并返回处理后的二进制数据
 //转换失败
 if ($new_data === false) {
     exit_status('error', 'p1:' . $img->errmsg());
 }
 $size = $img->getImageAttr();
 //覆盖加入3张图片
 $logo_ten_year_img = file_get_contents('../res/images/logo_ten_year110.png');
 $logo_zfb_img = file_get_contents('../res/images/logo_zfb100.png');
 $text_bg_img = file_get_contents('../res/images/text_back350.png');
 //清空$img数据
 $img->clean();
 //设定要用于合成的三张图片(如果重叠,排在后面的图片会盖住排在前面的图片)
 $img->setData(array(array($new_data, 0, 0, 1, SAE_TOP_LEFT), array($logo_ten_year_img, -10, 10, 1, SAE_BOTTOM_RIGHT), array($logo_zfb_img, -10, -10, 1, SAE_TOP_RIGHT), array($text_bg_img, 0, -47, 1, SAE_TOP_LEFT)));
 //执行合成
 $img->composite($size[0], $size[1]);
 //输出图片
 $new_data = $img->exec('jpg');
 if ($new_data === false) {
예제 #3
0
<?php

$link = mysql_connect(SAE_MYSQL_HOST_M . ':' . SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS);
if ($link) {
    mysql_select_db(SAE_MYSQL_DB, $link);
    $sql = "select count(*) from loli_images";
    $result = mysql_query($sql);
    $rand_id_max = mysql_fetch_row($result);
    $random_id = rand(1, $rand_id_max[0]);
    $sql = "SELECT loli_images_url FROM loli_images WHERE loli_images_id='{$random_id}'";
    $result = mysql_query($sql);
    //执行sql语句
    $row = mysql_fetch_row($result);
}
echo $row[0];
$img = new SaeImage();
$img->setData($row[0]);
$img->resize(200);
// 等比缩放到200宽
if ($new_data === false) {
    var_dump($img->errno(), $img->errmsg());
}
print_r($img);
echo "===============================================\n";
echo $row[0];