示例#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
<?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];