2

私はyiiで画像をアップロードし、アップロードした画像をトリミングして保存しようとしています。私が今まで達成したことは、フォームの送信時にアップロードできることですが、それをトリミングしたり、そのために使用jcropしたりすることを理解していません

public function actionCreate()
{
    $model=new Userprofile;
    if(isset($_POST['Userprofile']))
    {
    $model->attributes=$_POST['Userprofile'];
    $model->profilePic=CUploadedFile::getInstance($model,'profilePic');
    $ext = $model->profilePic->getExtensionName();
    $imagename=date('dmy').time().rand();
    $pp=$model->profilePic;
    $model->profilePic=$imagename.'.'.$ext;
    if($model->save())
        mkdir('profilepics/'.$model->id,0777);
        $pp->saveAs('profilepics/'.$model->id.'/'.$imagename.'.'.$ext);
        $this->redirect(array('view','id'=>$model->id));
    }
    $this->render('create',array('model'=>$model,));
}
4

2 に答える 2

3

jquery プラグイン imageAreaSelect を使用して、クライアント側でトリミングするための座標を取得できます。これがライブの例http://odyniec.net/projects/imgareaselect/です。

次に、座標をモデルの beforeSave に渡し、Imagick::cropImage() を使用してトリミングします (Imagick の代わりに、GD または必要な他のライブラリを使用できます)。

于 2012-05-15T09:00:36.727 に答える