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
Checking 50 pages in the tool "Checking the page"
190 ₽
The subscription is activated for 10 days and is linked to a specific site.
PRO subscription
3,500 pages per week in tools "Checking the page" and "Full site scan".
1 580 ₽
The subscription is activated for 30 days and you can scan any site.
Wallet
Additional pages that are credited to a separate balance. For checking large sites.
200 ₽
Number of pages
An active PRO subscription is required.
We use cookies. By continuing to use the site, you agree to the processing of personal data in accordance with privacy policy. I agree