# b-blocks/1.5.2/inc/gif.php

bBlocks – Essential Gutenberg Blocks &amp; Patterns Collection, version 1.5.2. 51 lines.

- Page: https://pluginprobe.com/plugins/b-blocks/1.5.2/code/inc/gif.php
- Raw: https://pluginprobe.com/plugins/b-blocks/1.5.2/raw/inc/gif.php
- Modified: 2021-10-18T14:05:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/b-blocks/1.5.2/code/inc/gif.php#L10-L20`.

```php
<?php
class BBlocksGIF extends BBlocks{
    public function __construct(){
        add_action( 'init', [$this, 'register'] );
    }

    function register(){
        $this::registerScripts( 'gif', array(
            'attributes'      => $this->attributes(),
            'render_callback' => [$this, 'render']
        ) );
    }

    function attributes(){
        return array(
            'align' => array( 'type' => 'string', 'default' => '' ),
            'cId' => array( 'type' => 'string', 'default' => '' ),

            'gif' => array( 'type' => 'object', 'default' => NULL ),
            'gifAlign' => array( 'type' => 'string', 'default' => 'center' ),
            'gifWidth' => array( 'type' => 'string', 'default' => '0px' )
        );
    }

    function render( $attributes ){
        extract( $attributes );

        // Generate Styles
        $gifStyle = new BBlocksStyleGenerator();
        $gifStyle::addStyle( "#bBlocksGif-$cId .bBlocksGif", array(
            'text-align' => $gifAlign
        ) );
        $gifStyle::addStyle( "#bBlocksGif-$cId .bBlocksGif figure", array(
            'width' => '0px' === $gifWidth || '0%' === $gifWidth || '0em' === $gifWidth ? 'auto' : $gifWidth
        ) );

        ob_start(); ?>
        <div class='wp-block-b-blocks-gif <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksGif-<?php echo esc_attr( $cId ); ?>'>
            <style><?php echo wp_kses( $gifStyle::renderStyle(), array() ); ?></style>

            <div class='bBlocksGif'>
                <figure>
                    <?php echo isset( $gif ) && $gif ? "<img src='". esc_url( $gif['images']['original']['url'] ?? '' ) ."' alt='". esc_attr( $gif['title'] ?? '' ) ."' />" : ''; ?>
                </figure>
            </div>
        </div>
        <?php $gifStyle::$styles = array(); // Empty styles
        return ob_get_clean();
    }
}
new BBlocksGIF();
```
