A
A
agent11562017-01-28 15:01:42
Yii
agent1156, 2017-01-28 15:01:42

Which extension to choose for photo cropping for yii2?

I installed yurkinx/yii2-image from github

<?php
                                                    $file=Yii::getAlias('@app/web/img/box3.jpg');
                                                    $image=Yii::$app->image->load($file);

                                                    echo   $image->resize(200,200)->rotate(30)->render();?>

... inserted, but a big black square with question marks pops up.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Timofeev, 2017-01-28
@agent1156

yurkinx/yii2-image is a great extension, and if you use Imagick instead of GD, then it's also optimal.
Maybe there is a term "cropping", I don't know it, but if we're talking about cropping a photo, then it's crop, not resize. Since the last one is a size change.
Well, the question is where do you use this code, at least you should add header("Content-Type: image/png");
But I do not think that rendering on the fly is the right idea, the server will grunt. It is better to use the extension not for rendering, but for creating thumbnails when uploading a photo. And then output using standard methods, a ready-made trimmed photo.

M
melnikov_m, 2017-01-28
@melnikov_m

There are a lot of components, for example, here's a good option. https://github.com/himiklab/yii2-easy-thumbnail-im...

A
agent1156, 2017-01-28
@agent1156

<?php if ($item->category == "ALANÆ LIFE"): ?>
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                <article class="post img-thumbnail with-border post-list">
                                    <div class="post-holder">
                                        <div class="row">
                                            <div class="col-md-8">
                                                <figure>
                                                    <a href="<?= Url::to(["/post/index", 'id' => $item->id]) ?>">
                                                        <?php if(empty($item->img)):?>
                                                        <?= Html::img("@backend/web/images/store/no-images.jpg")?></a>
                                                    <?php endif?>
                                                     <?php
                                                    $file=Yii::getAlias('@app/web/img/box3.jpg');
                                                    $image=Yii::$app->image->load($file);

                                                    echo    $image->resize(100,100);
                                                    ?>
                                                    <?= Html::img("@backend/web/images/store/{$item->img}") ?></a>
                                                    <ul class="post-meta">

                                                        <li>
                                                            <a href="<?= Url::to(["/post/index", 'id' => $item->id]) ?>">
                                                                <em><?= mb_substr($item->date, 8, 2, 'UTF-8')?></em>
                                                                <em>
                                                                    <?php
                                                                    $dateObj = \DateTime::createFromFormat('!m', mb_substr($item->date, 5, 2));
                                                                    echo mb_substr($dateObj->format('F'), 0, 3);
                                                                    ?>
                                                                </em>
                                                            </a>
                                                        </li>

                                                    </ul>
                                                </figure>
                                            </div>
                                            <div class="col-md-4">
                                                <div class="post-head">
                                                    <h2>
                                                        <a href="<?= Url::to(["/post/index", 'id' => $item->id]) ?>">
                                                            <?php switch (Yii::$app->language): case"ru-RU": ?>

                                                                        <?= $item->title_ru ?>
                                                                        <?php break ?>

                                                                    <?php
                                                            case"en-US":
                                                            ?>
                                                                            <?= $item->title_en ?>
                                                                            <?php break ?>

                                                                        <?php
                                                            case
                                                            "ir-IR":
                                                            ?>
                                                                            <?= $item->title_ir ?>
                                                                            <?php break ?>
                                                                        <?php endswitch?>
                                                        </a></h2>
                                                </div>

                                                <div class="description">
                                                    <p>
                                                        <?php switch (Yii::$app->language): case"ru-RU": ?>

                                                                <?= mb_substr('<p>' . $item->text_ru . '</p>', 0, 300, 'UTF-8') . ' <b>. . . </b>'; ?></p>
                                                    <?php break ?>

                                                            <?php
                                                    case"en-US":
                                                    ?>
                                                                <?= mb_substr('<p>' . $item->text_en . '</p>', 0, 300, 'UTF-8') . ' <b>. . . </b>'; ?></p>
                                                    <?php break ?>

                                                            <?php
                                                    case
                                                    "ir-IR":
                                                    ?>
                                                                <?= mb_substr('<p>' . $item->text_ir . '</p>', 0, 300, 'UTF-8') . ' <b>. . . </b>'; ?></p>
                                                    <?php break ?>
                                                            <?php endswitch?>
                                                    </p>
                                                </div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question