Lessons

Cropping monophonic fields in images

Often the image contains plain white frames. They do not carry any useful function and only increase the size of the image. This slows down the loading of the image and the page as a whole.

Remove the empty white edges from the image using the “Crop to content” function in graphic editors.

Demonstration of the work and code of the PHP function cropping images:

Demonstration
PHP code
HTML code
<?php
/**
 * Вам нужно установить imagemagick.
 * Для убунту это делается так apt install imagemagick
 */

$data = exec("magick photo.jpg -trim photo_crop.jpg", $output);
$data = array_pop($output);
?><!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            .grid {
                display: grid;
                grid-template-columns: 1fr 1fr 1fr;
                grid-gap: 10px;
            }
            img {
                width: 100%;
                border:2px solid black;
                border-radius: 5px;
            }
        </style>
    </head>
    <body>
        <div class="grid">
            <div>
                Исходная картинка
                <img src="./photo.jpg" />
            </div>
            <div>
                Обрезанная картинка
                <img src="./photo_crop.jpg" />
            </div>
        </div>
    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            .grid {
                display: grid;
                grid-template-columns: 1fr 1fr 1fr;
                grid-gap: 10px;
            }
            img {
                width: 100%;
                border:2px solid black;
                border-radius: 5px;
            }
        </style>
    </head>
    <body>
        <div class="grid">
            <div>
                Исходная картинка
                <img src="./photo.jpg" />
            </div>
            <div>
                Обрезанная картинка
                <img src="./photo_crop.jpg" />
            </div>
        </div>
    </body>
</html>

PRO subscription for working with the service

Promo
To prepare a commercial offer.
190 ₽
50 pages for 10 days
  • 1 page gives 1 tool launch Checking the page.
  • Purchased for a specific site
  • Restrictions on other tools remain the same
PRO subscription
For regular work on a site or a group of sites.
1 580 ₽
3,500 pages per week. The subscription period is 1 month.
Wallet
A separate page balance that complements the PRO subscription balance.
190 ₽
Number of pages
  • An active PRO subscription is required to use the wallet balance
We use cookies. By continuing to use the site, you agree to the processing of personal data in accordance with privacy policy. I agree