/** * 进行图片处理操作 * * @param string $format 图片格式,支持gif和jpg * @param bool $display 是否直接输出,false:不输出,true:输出,默认false * @return void * @author Lijun */ public function exec($format = "jpg", $display = false) { if (self::imageNull()) { return false; } if ($format !== "jpg" and $format !== "gif") { self::$_errno = SAE_ErrParameter; self::$_errmsg = "format must be one of 'jpg' and 'gif'"; return false; } else { self::$_format = $format; } if (self::$_post[0]["act"] == "composite" && is_array(self::$_img_data)) { foreach (self::$_img_data as $k => $v) { self::$_img_data[$k][0] = base64_encode($v[0]); //unset($v[0]); } array_unshift(self::$_post, array("format" => $format, "imagedata" => self::$_img_data)); } else { array_unshift(self::$_post, array("format" => $format, "imagedata" => base64_encode(self::$_img_data))); } if (self::$_post[1]["act"] == "composite" && !is_array(self::$_post[0]["imagedata"])) { self::$_errno = SAE_ErrParameter; self::$_errmsg = "composite imagedata must be an array, pls see doc:"; return false; } if (self::$_post[1]["act"] != "composite" && is_array(self::$_post[0]["imagedata"])) { self::$_errno = SAE_ErrParameter; self::$_errmsg = "imagedata is array only when composite image and composite must be the first operation"; return false; } foreach (self::$_post as $k => $a) { if (isset($a["act"]) && $a["act"] == 'composite' && $k != 1) { self::$_errno = SAE_ErrParameter; self::$_errmsg = "composite operation must be the first operation!"; return false; } } $tobepost = json_encode(self::$_post); $ret = self::postImgData(array("saeimg" => $tobepost)); if ($ret && $display) { header("Content-Type: image/{$format}"); echo $ret; return true; } else { return $ret; } }