You are here

function _pwa_apple_create_image_base in Progressive Web App 7.2

1 call to _pwa_apple_create_image_base()
_pwa_apple_get_spalsh_screen_href in includes/pwa.apple.inc

File

includes/pwa.apple.inc, line 59

Code

function _pwa_apple_create_image_base() {
  $manifest = pwa_file_data('manifest');
  $base_folder = 'public://pwa/apple';
  if ($icon_src = array_search('512x512', array_column($manifest['icons'], 'sizes', 'src'))) {
    $src = DRUPAL_ROOT . parse_url($icon_src, PHP_URL_PATH);
    $image = image_load($src);
    $target = imagecreatetruecolor(2732, 2732);

    // Get background color from the icon, take from the edge in case there
    // is a gradient going on.
    $color_index = imagecolorat($image->resource, 1, 1);
    $color = imagecolorsforindex($image->resource, $color_index);
    $background = imagecolorallocate($target, $color['red'], $color['green'], $color['blue']);
    imagefill($target, 0, 0, $background);

    // Because we know all the sizes, possible to hardcode the values here.
    imagecopymerge($target, $image->resource, 1110, 1110, 0, 0, 512, 512, 100);
    if ($directory = _pwa_apple_create_folder($base_folder)) {
      imagepng($target, $directory . '/drusplash.png');
    }
    imagedestroy($target);
  }
}