function responsive_bg($img_field)
{
    // Set the three images sizes to be used
    $img_information = wp_get_attachment_metadata($img_field);
    $path = '/wp-content/uploads/' . substr($img_information['file'], 0, 8);
    $file = substr($img_information['file'], 8);
    $large_version = $img_information['sizes']['large-hero-png']['file'] !== null ? $path . $img_information['sizes']['large-hero-png']['file'] : $path . $file;
    $medium_version = $img_information['sizes']['medium-hero-png']['file'] !== null ? $path . $img_information['sizes']['medium-hero-png']['file'] : $path . $file;
    $small_version = $img_information['sizes']['small-hero-png']['file'] !== null ? $path . $img_information['sizes']['small-hero-png']['file'] : $path . $file;
    $relative_path = get_attached_file($img_field);
    $relative_path = str_replace(basename($relative_path), '', $relative_path);
    // Assign the image sizes into an array
    $bg_images = array('default' => $path . $file, 'mobile' => $small_version, '(min-width:320px) and (-webkit-device-pixel-ratio: 2)' => $medium_version, '(min-width:320px) and (-webkit-device-pixel-ratio: 3)' => $large_version, '(min-width:640px)' => $medium_version, '(min-width:640px) and (-webkit-device-pixel-ratio: 2)' => $large_version, '(min-width:1000px)' => $large_version, '(min-width:1000px) and (-webkit-device-pixel-ratio: 2)' => $path . $file, '(min-width:1200px)' => $path . $file);
    $the_small_preview = $bg_images['mobile'];
    // Take the $bg_images array and run it through encoding
    // so the array is readable by the browser (defined below)
    $bg_images = format_responsive_image_array($bg_images);
    $background_color = !empty(get_field('image_preload_color', $img_field)) ? get_field('image_preload_color', $img_field) : get_field('brand_image_preloading_color', 'options');
    $background_color = $background_color == '' ? '#ECF1F3' : $background_color;
    // Echo the cleaned image array, but surround it with
    // 'data-bgimg' so JS can run on it to replace images
    // when the browser is resized
    echo ' data-bgimg="' . $bg_images . '" style="background-color:' . $background_color . ';background-image:url(\'' . base64_encode_image($relative_path . basename($small_version), 'jpg') . '\')" ';
}
Exemple #2
0
function base64_encode_image($filename, $filetype)
{
    $filename = trim($filename);
    $imgbinary = file_get_contents($filename);
    return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary);
}
$callback = $_GET['callback'];
$url = trim(urldecode($_GET['url']));
$urlInfo = parse_url($url);
$info = explode('.', $urlInfo['path']);
$type = $info[count($info) - 1];
$type = strtolower($type);
if ($type == 'jpeg') {
    $type = 'jpg';
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_DNS_USE_GLOBAL_CACHE, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
define('CURLOPT_IPRESOLVE', 113);
define('CURL_IPRESOLVE_V4', 1);
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$img = curl_exec($curl);
curl_close($curl);
//exit;
//echo file_get_contents($url);
//exit();
$json = json_encode(array('data' => base64_encode_image($url, $type)));
echo $callback . '(' . $json . ')';
Exemple #3
0
?>
                                                    </ul>

                                            </div>
                                        </div>
                                        <div class="col-md-4 general_photo m-b text-center">
                                            <div class="panel-heading font-bold">Основное фото</div>
                                            <!--<div class="panel-heading font-normal">Максимальный размер загружаемых фотографий: 525х384px</div>-->
                                            <label for="image" class="upload_photo">
                                                <!--                                                <form id="form" action="upload.php" method="post" enctype="multipart/form-data">-->
                                                <?php 
if (!empty($arr_img)) {
    $first_val = reset($arr_img);
    $path = '../img/' . $first_val;
    if (file_exists($path)) {
        $image = base64_encode_image($path, 'jpeg');
        echo '<input type="hidden" name="old_image"  value="' . $first_val . '"/>';
        echo '<input type="hidden"  value="' . $image . '"/>';
    } else {
        $image = '../img/photo.jpg';
    }
}
?>
                                                <div><img alt="" id="image_preview"
                                                          src="<?php 
echo isset($image) ? $image : "../img/photo.jpg";
?>
"/>
                                                    <select class="form-control m-b"
                                                            name="color_main">
                                                        <option class="ntSaveForms" value="0"></option>