{"id":43807256,"url":"https://github.com/crazykun/yii2-cropper","last_synced_at":"2026-02-05T23:03:05.192Z","repository":{"id":56956539,"uuid":"147165201","full_name":"crazykun/yii2-cropper","owner":"crazykun","description":"yii2图片裁剪插件","archived":false,"fork":false,"pushed_at":"2018-09-11T06:02:41.000Z","size":728,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-13T02:53:04.274Z","etag":null,"topics":["cropper","php","yii2"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crazykun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-03T07:07:06.000Z","updated_at":"2019-09-19T09:28:58.000Z","dependencies_parsed_at":"2022-08-21T04:40:19.399Z","dependency_job_id":null,"html_url":"https://github.com/crazykun/yii2-cropper","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/crazykun/yii2-cropper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazykun%2Fyii2-cropper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazykun%2Fyii2-cropper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazykun%2Fyii2-cropper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazykun%2Fyii2-cropper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crazykun","download_url":"https://codeload.github.com/crazykun/yii2-cropper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazykun%2Fyii2-cropper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29137753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T23:02:30.544Z","status":"ssl_error","status_checked_at":"2026-02-05T23:02:24.945Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cropper","php","yii2"],"created_at":"2026-02-05T23:03:04.514Z","updated_at":"2026-02-05T23:03:05.187Z","avatar_url":"https://github.com/crazykun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yii2-cropper\nYii2 Image Cropper InputWidget\n\n[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%205.4-8892BF.svg)](https://php.net/)\n\n\u003ca href=\"https://fengyuanchen.github.io/cropper/\" target=\"_blank\"\u003eCropper.js  v4.0.0\u003c/a\u003e - Bootstrap Cropper (recommended) (already included).\n\nFeatures\n------------\n+ Image Crop 图片裁剪\n+ Image Rotate 图片旋转\n+ Image Flip  图片翻转\n+ Image Zoom 图片缩放\n+ Image Reset 图片重置\n+ Coordinates 图片坐标\n+ Image Sizes Info \n+ Base64 Data 图片base64编码\n+ Upload 图片上传\n+ Delete Img 删除图片\n\nDemo images\n-----\n\n![效果图](https://raw.githubusercontent.com/crazykun/yii2-cropper/master/demo.png)\n\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist coldlook/yii2-cropper \"dev-master\"\n```\n\nor add\n\n```\n\"coldlook/yii2-cropper\": \"dev-master\"\n```\n\nto the require section of your `composer.json` file.\n\n\nUsage\n-----\n\n\nLet's add  in your controller file\n````php\n\n    public function actionBase64Img(){\n        $image=$this-\u003eparam('image');\n        $fileName=$this-\u003esave_base64_image($image);\n        if(!$fileName){\n            return $this-\u003eajaxMessage(1,'上传失败');\n        }\n        $successPath = Yii::$app-\u003eparams['imageUploadSuccessPath'] . date('Ymd') . '/';\n     \n        if ($successPath === false) {\n            return $this-\u003eajaxMessage(1,'上传失败');\n        }else{\n            return $this-\u003eajaxMessage(0,'上传成功',[\n                'url' =\u003e $successPath,\n                'attachment' =\u003e $successPath\n            ]);\n        }\n    }\n\n    /**\n     * [将Base64图片转换为本地图片并保存]\n     * @param  [Base64] $save_base64_image [要保存的Base64]\n     * @param  [目录] $path [要保存的路径]\n     */\n    public function save_base64_image($base64_image_content,$path=''){\n        if(!$path){\n            $path = Yii::$app-\u003eparams['imageUploadRelativePath'] . date('Ymd') . '/';\n        }\n        //匹配出图片的格式\n        if (preg_match('/^(data:\\s*image\\/(\\w+);base64,)/', $base64_image_content, $result)){\n            $type = $result[2];\n            if (!is_dir($path)) {\n                FileHelper::createDirectory($path, 0777);\n            }\n            $fileName= date('YmdHis') . rand(100000, 999999). '.' .$type;\n\n            if (file_put_contents($path.$fileName, base64_decode(str_replace($result[1], '', $base64_image_content)))){\n                return $fileName;\n            }else{\n                return false;\n            }\n        }else{\n            return false;\n        }\n    }\n\n\n````\n\n\nSimple usage in _form file\n-----\n````php\n echo $form-\u003efield($model, '_image')-\u003ewidget(\\coldlook\\cropper\\Cropper::className(), [\n        'label' =\u003e '选择图片', \n        'imageUrl' =\u003e $model-\u003e_image,\n        'cropperOptions' =\u003e [\n            'width' =\u003e 255, \n            'height' =\u003e 150, \n            'preview' =\u003e [\n                'width' =\u003e 255, \n                'height' =\u003e 150, \n            ],\n        ],         \n        'uploadOptions'=\u003e[\n            'url'=\u003e'/admin/upload/base64-img',\n            'response'=\u003e'res.result.url'\n        ]\n]);\n````\n\n\n\nAdvanced usage in _form file\n-----\n````php\n echo $form-\u003efield($model, '_image')-\u003elable(\"封面图1(非必填,尺寸:宽*高 建议尺寸225px*150px)\")-\u003ewidget(\\coldlook\\cropper\\Cropper::className(), [\n    /*\n     * elements of this widget\n     *\n     * buttonId          = #cropper-select-button-$uniqueId\n     * previewId         = #cropper-result-$uniqueId\n     * modalId           = #cropper-modal-$uniqueId\n     * imageId           = #cropper-image-$uniqueId\n     * inputChangeUrlId  = #cropper-url-change-input-$uniqueId\n     * closeButtonId     = #close-button-$uniqueId\n     * cropButtonId      = #crop-button-$uniqueId\n     * browseInputId     = #cropper-input-$uniqueId // fileinput in modal\n    */\n    'uniqueId' =\u003e 'image_cropper', // will create automaticaly if not set\n\n    // you can set image url directly\n    // you will see this image in the crop area if is set\n    // default null\n    'imageUrl' =\u003e Yii::getAlias('@web/image.jpg'),\n    \n    'cropperOptions' =\u003e [\n        'width' =\u003e 100, // must be specified\n        'height' =\u003e 100, // must be specified\n\n        // optional\n        // url must be set in update action\n        'preview' =\u003e [\n            'url' =\u003e '', // (!empty($model-\u003eimage)) ? Yii::getAlias('@uploadUrl/'.$model-\u003eimage) : null\n            'width' =\u003e 100, // must be specified // you can set as string '100%'\n            'height' =\u003e 100, // must be specified // you can set as string '100px'\n        ],\n\n        // optional // default following code\n        // you can customize \n        'buttonCssClass' =\u003e 'btn btn-primary',\n\n        // optional // defaults following code\n        // you can customize \n        'icons' =\u003e [\n            'browse' =\u003e '\u003ci class=\"fa fa-image\"\u003e\u003c/i\u003e',\n            'crop' =\u003e '\u003ci class=\"fa fa-crop\"\u003e\u003c/i\u003e',\n            'close' =\u003e '\u003ci class=\"fa fa-crop\"\u003e\u003c/i\u003e',       \n            'zoom-in' =\u003e '\u003ci class=\"fa fa-search-plus\"\u003e\u003c/i\u003e',\n            'zoom-out' =\u003e '\u003ci class=\"fa fa-search-minus\"\u003e\u003c/i\u003e',\n            'rotate-left' =\u003e '\u003ci class=\"fa fa-rotate-left\"\u003e\u003c/i\u003e',\n            'rotate-right' =\u003e '\u003ci class=\"fa fa-rotate-right\"\u003e\u003c/i\u003e',\n            'flip-horizontal' =\u003e '\u003ci class=\"fa fa-arrows-h\"\u003e\u003c/i\u003e',\n            'flip-vertical' =\u003e '\u003ci class=\"fa fa-arrows-v\"\u003e\u003c/i\u003e',\n            'move-left' =\u003e '\u003ci class=\"fa fa-arrow-left\"\u003e\u003c/i\u003e',\n            'move-right' =\u003e '\u003ci class=\"fa fa-arrow-right\"\u003e\u003c/i\u003e',\n            'move-up' =\u003e '\u003ci class=\"fa fa-arrow-up\"\u003e\u003c/i\u003e',\n            'move-down' =\u003e '\u003ci class=\"fa fa-arrow-down\"\u003e\u003c/i\u003e',\n            'reset' =\u003e '\u003ci class=\"fa fa-refresh\"\u003e\u003c/i\u003e',\n            'delete' =\u003e '\u003ci class=\"fa fa-trash\"\u003e\u003c/i\u003e',\n        ],\n        // you can customize your upload options\n        'uploadOptions'=\u003e[\n            'url'=\u003e'/upload/base64-img',\n            'response'=\u003e'res.result.url'\n        ]\n    ],\n\n    // optional // defaults following code\n    // you can customize \n    'label' =\u003e '选择图片', \n    \n    // optional // default following code\n    // you can customize \n    'template' =\u003e '{button}{preview}',\n\n ]);\n````\n\n\n\n\n\njsOptions[]\n-----\n````php\n echo $form-\u003efield($model, '_image')-\u003ewidget(\\coldlook\\cropper\\Cropper::className(), [\n    'cropperOptions' =\u003e [\n        'width' =\u003e 100, // must be specified\n        'height' =\u003e 100, // must be specified\n     ],\n     'jsOptions' =\u003e [\n        'pos' =\u003e View::POS_END, // default is POS_END if not specified\n        'onClick' =\u003e 'function(event){\n              // when click crop or close button \n              // do something \n        }'        \n     ],\n]);\n````\n\n\n\nNotes\n-----\n\nYou can set crop image directly with javascript \n\nSample:\n````\n$('button').click(function() {\n   // #cropper-modal-$unique will show automatically when click the button\n   \n   // you must set uniqueId on widget\n   $('#cropper-url-change-input-' + uniqueId).val('image.jpeg').trigger('change');   \n});\n````\n\nThx\n-----\n\n [bilginnet](https://github.com/bilginnet/yii2-cropper).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrazykun%2Fyii2-cropper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrazykun%2Fyii2-cropper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrazykun%2Fyii2-cropper/lists"}