cozumel/yii2-image-cropper
Composer 安装命令:
composer require cozumel/yii2-image-cropper
包简介
A simple wrapper for the imgAreaSelect jquery plugin
README 文档
README
A simple wrapper for the imgAreaSelect jquery plugin
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist cozumel/yii2-image-cropper "*"
or add
"cozumel/yii2-image-cropper": "*"
to the require section of your composer.json file.
Usage
Once the extension is installed, simply use it in your code by :
<?= \cozumel\cropper\ImageCropper::widget(); ?>
Example
View File:
<?= \cozumel\cropper\ImageCropper::widget(['id' => 'user_profile_photo']); ?>
Where user_profile_photo is the id of the image to use.
Html in view file:
The main image you will be cropping:
<img width="<?= $width; ?>" height="<?= $height; ?>" max-width="<?=$max_width;?>" class="border" id="user_profile_photo" alt="<?=alt_text;?>" src="<?= image_source; ?>">
The preview image: (the ids here are fixed, and the 75px must be stated but can be changed)
<div style="display:none;" id="js_photo_preview"> <strong>Preview:</strong> <div class="p_2"> <div id="js_profile_photo_preview_container" style="position:relative; overflow:hidden; width:75px; height:75px; border:1px #000 solid;"> <img width="<?= $width; ?>" height="<?= $height; ?>" class="border" id="js_profile_photo_preview" alt="<?=$alt_text;?>" src="<?= $image_source; ?>" style=""> </div> </div> </div>
The form to send the information to your controller:
<?php $form = ActiveForm::begin(['action' => Yii::$app->urlManager->createUrl(['your/url/here']), 'options' => ['id' => 'crop_form'], ]); ?> <div><input type="hidden" id="x1" value="" name="x1"></div> <div><input type="hidden" id="y1" value="" name="y1"></div> <div><input type="hidden" id="x2" value="" name="x2"></div> <div><input type="hidden" id="y2" value="" name="y2"></div> <div><input type="hidden" id="w" value="" name="w"></div> <div><input type="hidden" id="h" value="" name="h"></div> <div><input type="hidden" value="<?= $width; ?>" name="image_width"></div> <div><input type="hidden" value="<?= $height; ?>" name="image_height"></div> <div style="margin-top:10px;"> <input type="submit" class="button" id="js_save_profile_photo" value="Save Avatar"> </div> <?php ActiveForm::end(); ?>
Javascript to submit the form:
$(document).ready(function () { $(document.body).on('submit', '#crop_form', function (e) { var frm = $(this); //just sent text $.ajax({ type: frm.attr('method'), url: frm.attr('action'), dataType: 'json', data: frm.serialize(), success: function (data) { if (data) { //do something } }, }); return false; }); });
Your controller function:
$request = Yii::$app->request; $x1 = $request->post('x1'); $x2 = $request->post('x2'); $y1 = $request->post('y1'); $y2 = $request->post('y2'); $h = $request->post('h'); $w = $request->post('w'); $image_height = $request->post('image_height'); $image_width = $request->post('image_width'); if (empty($w)) { //nothing selected return; } $image = imagecreatefromjpeg($image_source); $width = imagesx($image); $height = imagesy($image); $resized_width = ((int) $x2) - ((int) $x1); $resized_height = ((int) $y2) - ((int) $y1); $resized_image = imagecreatetruecolor($resized_width, $resized_height); imagecopyresampled($resized_image, $image, 0, 0, (int) $x1, (int) $y1, $width, $height, $width, $height); imagejpeg($resized_image, $image_source);
cozumel/yii2-image-cropper 适用场景与选型建议
cozumel/yii2-image-cropper 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 113.89k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「crop」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cozumel/yii2-image-cropper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cozumel/yii2-image-cropper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cozumel/yii2-image-cropper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A bundle providing fields for image upload with jquery upload and image cropping with jcrop for symfony2
A custom URL rule class for Yii 2 which allows to create translated URL rules
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
A image cropping field for kirby.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 113.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2016-04-15