Code Monkey home page Code Monkey logo

Comments (11)

hfageeh avatar hfageeh commented on September 28, 2024 1

The 'icon-framework' option has not been setup in Yii params. Check your configuration file.

from yii2-widget-cropbox.

bupy7 avatar bupy7 commented on September 28, 2024

What version of cropbox? And could you give me your code?

from yii2-widget-cropbox.

hfageeh avatar hfageeh commented on September 28, 2024

3.0

from yii2-widget-cropbox.

hfageeh avatar hfageeh commented on September 28, 2024

view:

<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
<?= $form->field($model, 'image')->widget(Cropbox::className(), [
'attributeCropInfo' => 'crop_info',

]); ?>

<?= $form->field($model, 'order')->textInput() ?>
field($model, 'ar_groupname')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'en_groupname')->textInput(['maxlength' => true]) ?>



<div class="form-group">
    <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>

from yii2-widget-cropbox.

hfageeh avatar hfageeh commented on September 28, 2024

model:

100], [['imageFile'], 'string', 'max' => 255], [ 'image', 'image', 'extensions' => ['jpg', 'jpeg', 'png', 'gif'], 'mimeTypes' => ['image/jpeg', 'image/pjpeg', 'image/png', 'image/gif'], ], ['crop_info', 'safe'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'projgroup_id' => Yii::t('app', 'Projgroup ID'), 'ar_groupname' => Yii::t('app', 'Arabic Groupname'), 'en_groupname' => Yii::t('app', 'English Groupname'), 'imageFile' => Yii::t('app', 'Image File'), 'image' => Yii::t('app', 'Groupimg'), 'created' => Yii::t('app', 'Created'), 'createdby' => Yii::t('app', 'Createdby'), 'modified' => Yii::t('app', 'Modified'), 'modifiedby' => Yii::t('app', 'Modifiedby'), 'order' => Yii::t('app', 'Order'), ]; } /** * @return \yii\db\ActiveQuery */ public function getProjects() { return $this->hasMany(Projects::className(), ['projgroup_id' => 'projgroup_id']); } public function afterSave($insert, $changedAttributes) { // open image $image = Image::getImagine()->open($this->image->tempName); // rendering information about crop of ONE option $cropInfo = Json::decode($this->crop_info)[0]; $cropInfo['dWidth'] = (int)$cropInfo['dWidth']; //new width image $cropInfo['dHeight'] = (int)$cropInfo['dHeight']; //new height image $cropInfo['x'] = $cropInfo['x']; //begin position of frame crop by X $cropInfo['y'] = $cropInfo['y']; //begin position of frame crop by Y // Properties bolow we don't use in this example //$cropInfo['ratio'] = $cropInfo['ratio'] == 0 ? 1.0 : (float)$cropInfo['ratio']; //ratio image. //$cropInfo['width'] = (int)$cropInfo['width']; //width of cropped image //$cropInfo['height'] = (int)$cropInfo['height']; //height of cropped image //$cropInfo['sWidth'] = (int)$cropInfo['sWidth']; //width of source image //$cropInfo['sHeight'] = (int)$cropInfo['sHeight']; //height of source image //delete old images $oldImages = FileHelper::findFiles(Yii::getAlias('@path/to/save/image'), [ 'only' => [ $this->id . '.*', 'thumb_' . $this->id . '.*', ], ]); for ($i = 0; $i != count($oldImages); $i++) { @Unlink($oldImages[$i]); } //saving thumbnail $newSizeThumb = new Box($cropInfo['dWidth'], $cropInfo['dHeight']); $cropSizeThumb = new Box(200, 200); //frame size of crop $cropPointThumb = new Point($cropInfo['x'], $cropInfo['y']); $pathThumbImage = Yii::getAlias('@path/to/save/image') . '/thumb_' . $this->id . '.' . $this->image->getExtension(); $image->resize($newSizeThumb) ->crop($cropPointThumb, $cropSizeThumb) ->save($pathThumbImage, ['quality' => 100]); //saving original $this->image->saveAs( Yii::getAlias('@path/to/save/image') . '/' . $this->id . '.' . $this->image->getExtension() ); } }

from yii2-widget-cropbox.

hfageeh avatar hfageeh commented on September 28, 2024

controller:
public function actionCreate()
{
$model = new Projectsgroups();
//$upload = new UploadForm();
if ($model->load(Yii::$app->request->post()))
{
// get uploaded file information
$groupName = strtolower($model->en_groupname);
$imageName = str_replace(' ', '',$groupName );;
$model->image = UploadedFile::getInstance($model, 'image');
$model->image->saveAs('../../frontend/web/images/project/' . $imageName.'.'.$model->image->extension);

        // save the path in DB 
        $model->imageFile = $imageName.'.'.$model->image->extension;
        $model->created = date('Y-m-d h:m:s');
        $model->save();
        
   
        return $this->redirect(['view', 'id' => $model->projgroup_id]);
        } else {
        return $this->render('create', [
            'model' => $model,
        ]);
    }
}

from yii2-widget-cropbox.

bupy7 avatar bupy7 commented on September 28, 2024

Wow, very dirty... You should wrap you code in markdown code tag, please.

Could you give me screenshot of the error message?

from yii2-widget-cropbox.

hfageeh avatar hfageeh commented on September 28, 2024

error

from yii2-widget-cropbox.

bupy7 avatar bupy7 commented on September 28, 2024

It's a bug. You can fix it following code or use 4 version of cropbox:

<?= $form->field($model, 'image')->widget(Cropbox::className(), [
    'attributeCropInfo' => 'crop_info',
    'optionsCropbox' => [
        'cropSettings' => [],
    ],
]); ?>

from yii2-widget-cropbox.

bupy7 avatar bupy7 commented on September 28, 2024

https://github.com/kartik-v/yii2-icons#global-setup

from yii2-widget-cropbox.

hfageeh avatar hfageeh commented on September 28, 2024

its work you the man 💯

from yii2-widget-cropbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.