_color_render_images($theme, &$info, &$paths, $palette)
Renders images that match a given palette.
File
- core/modules/color/color.module, line 593
- Allows users to change the color scheme of themes.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | function _color_render_images( $theme , & $info , & $paths , $palette ) { // Prepare template image. $source = $paths [ 'source' ] . '/' . $info [ 'base_image' ]; $source = imagecreatefrompng( $source ); $width = imagesx( $source ); $height = imagesy( $source ); // Prepare target buffer. $target = imagecreatetruecolor( $width , $height ); imagealphablending( $target , TRUE); // Fill regions of solid color. foreach ( $info [ 'fill' ] as $color => $fill ) { imagefilledrectangle( $target , $fill [0], $fill [1], $fill [0] + $fill [2], $fill [1] + $fill [3], _color_gd( $target , $palette [ $color ])); } // Render gradients. foreach ( $info [ 'gradients' ] as $gradient ) { // Get direction of the gradient. if (isset( $gradient [ 'direction' ]) && $gradient [ 'direction' ] == 'horizontal' ) { // Horizontal gradient. for ( $x = 0; $x < $gradient [ 'dimension' ][2]; $x ++) { $color = _color_blend( $target , $palette [ $gradient [ 'colors' ][0]], $palette [ $gradient [ 'colors' ][1]], $x / ( $gradient [ 'dimension' ][2] - 1)); imagefilledrectangle( $target , ( $gradient [ 'dimension' ][0] + $x ), $gradient [ 'dimension' ][1], ( $gradient [ 'dimension' ][0] + $x + 1), ( $gradient [ 'dimension' ][1] + $gradient [ 'dimension' ][3]), $color ); } } else { // Vertical gradient. for ( $y = 0; $y < $gradient [ 'dimension' ][3]; $y ++) { $color = _color_blend( $target , $palette [ $gradient [ 'colors' ][0]], $palette [ $gradient [ 'colors' ][1]], $y / ( $gradient [ 'dimension' ][3] - 1)); imagefilledrectangle( $target , $gradient [ 'dimension' ][0], $gradient [ 'dimension' ][1] + $y , $gradient [ 'dimension' ][0] + $gradient [ 'dimension' ][2], $gradient [ 'dimension' ][1] + $y + 1, $color ); } } } // Blend over template. imagecopy( $target , $source , 0, 0, 0, 0, $width , $height ); // Clean up template image. imagedestroy( $source ); // Cut out slices. foreach ( $info [ 'slices' ] as $file => $coord ) { list( $x , $y , $width , $height ) = $coord ; $base = drupal_basename( $file ); $image = drupal_realpath( $paths [ 'target' ] . $base ); // Cut out slice. if ( $file == 'screenshot.png' ) { $slice = imagecreatetruecolor(150, 90); imagecopyresampled( $slice , $target , 0, 0, $x , $y , 150, 90, $width , $height ); \Drupal::configFactory()->getEditable( 'color.theme.' . $theme ) ->set( 'screenshot' , $image ) ->save(); } else { $slice = imagecreatetruecolor( $width , $height ); imagecopy( $slice , $target , 0, 0, $x , $y , $width , $height ); } // Save image. imagepng( $slice , $image ); imagedestroy( $slice ); $paths [ 'files' ][] = $image ; // Set standard file permissions for webserver-generated files drupal_chmod( $image ); // Build before/after map of image paths. $paths [ 'map' ][ $file ] = $base ; } // Clean up target buffer. imagedestroy( $target ); } |
Please login to continue.