<?php
require_once APPLICATION_PATH.'/models/tablemodel/Image.php';
require_once APPLICATION_PATH.'/helpers/compress.php';
class ImageController extends Zend_Controller_Action{
public function init1(){
parent::init();
}
public function indexAction(){
//取得上傳檔案資訊
$filename=$_FILES['image']['name'];
$tmpname=$_FILES['image']['tmp_name'];
$filetype=$_FILES['image']['type'];
$filesize=$_FILES['image']['size'];
$file=NULL;
if(isset($_FILES['image']['error'])){
if($_FILES['image']['error']==0){
$instr = fopen($tmpname,"rb" );
$file = addslashes(fread($instr,filesize($tmpname)));
}
}
//echo $file;
$url = constant("APPLICATION_PATH").DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'application.ini';
$dbconfig = new Zend_Config_Ini($url, "[[mysql]]");
$db = Zend_Db::factory( $dbconfig->db );
$db->query('SET NAMES UTF8');
$samll = 'temp.jpg';
imagecrop($_FILES['image']['tmp_name'],$samll,$_FILES['image']['type'],475,300);
$instr = fopen($samll,"rb" );
$fileSmall = addslashes(fread($instr,filesize($samll)));
header("Content-type: image/jpeg");
echo stripslashes($fileSmall);
exit;
}
public function showAction(){
$image = new Image();
$data = $image->find(29);
header("Content-type: image/jpeg");
//$srcPic = $data->toArray()[0]['pic'];
//imagejpeg (imagecreatefromjpeg("D:\\rdn_4f3311b77ca1d.jpg"),null,100);
//imagejpeg ($data->toArray()[0]['pic'],null,100);
echo ($data->toArray()[0]['pic']);
//RarImag::makeThumb("D:\\rdn_4f3311b77ca1d.jpg", 425, 300);
//echo $dstFile;
exit;
}
}
?>
<?php
function imagecrop($img_name,$newname, $type, $modwidth, $modheight) {
list ( $width, $height ) = getimagesize ( $img_name ); // get width & height
// in
// array list
$tn = imagecreatetruecolor ( $modwidth, $modheight );
if (! strcmp ( "image/png", $type )) {
imagealphablending ( $tn, false ); // For transparent BackGround
imagesavealpha ( $tn, true );
}
if (! strcmp ( "image/jpg", $type ) || ! strcmp ( "image/jpeg", $type ) || ! strcmp ( "image/pjpeg", $type ))
$src_img = imagecreatefromjpeg ( $img_name );
if (! strcmp ( "image/png", $type ))
$src_img = imagecreatefrompng ( $img_name );
if (! strcmp ( "image/gif", $type ))
$src_img = imagecreatefromgif ( $img_name );
imagecopyresampled ( $tn, $src_img, 0, 0, 0, 0, $modwidth, $modheight, $width, $height );
if (! strcmp ( "image/png", $type )) {
imagesavealpha ( $src_img, true );
$ok = imagepng ( $tn, $newname );
} else if (! strcmp ( "image/gif", $type )) {
$ok = imagegif ( $tn, $newname );
} else {
$ok = imagejpeg ( $tn, $newname );
}
if ($ok == 1) {
//return "<img src=" . $_FILES ['image'] ['name'] . " border='0'>";
return $newname;
}
}
?>
最終更新:2013年08月06日 17:04