1

我第一次使用 jcrop。试图通过 jcrop 教程,我得到一个黑色的裁剪图像。这是来自 deepliquid 的演示脚本,带有适当的 yii 更改。这是我裁剪和显示图像的裁剪操作

public function actionCrop()
    {
        $image_record = Images::model()->findByPk(Yii::app()->request->getParam('image'));
        $imageUrl = '/images/uploads/'.$image_record->id.'/'.$image_record->image;

        $model = new Crop;

        if(isset($_POST['Crop']))
        {
            $model->attributes=$_POST['Crop'];
            if($model->validate())
            {
                // form inputs are valid, do something here

                $targ_w = $targ_h = 500;
                $jpeg_quality = 90;

                $src = $this->createAbsoluteUrl($imageUrl);
                $img_r = imagecreatefromjpeg($src);
                $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

                imagecopyresampled($dst_r,$img_r,0,0,$model->x1,$model->y1,
                    $targ_w,$targ_h,$model->w,$model->h);

                header('Content-type: image/jpeg');
                imagejpeg($dst_r, null, $jpeg_quality);


            }
        }
4

0 回答 0