PHP code example of yongfook / bannerbear

1. Go to this page and download the library: Download yongfook/bannerbear library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yongfook / bannerbear example snippets




$bb = new Bannerbear\BannerbearClient("your api key");

$bb = new Bannerbear\BannerbearClient();

$account = $bb->account();

$bb->create_image("template uid", [
    "modifications" => [
        [
            "name" => "headline",
            "text" => "Hello world!",
        ],
        [
            "name" => "photo",
            "image_url" =>
            "https://images.unsplash.com/photo-1555400038-63f5ba517a47?w=1000&q=80",
        ],
    ],
]);

$bb->create_image(
  "template uid",
  [
    "modifications" => [
        [
            "name" => "headline",
            "text" => "Hello world!",
        ],
        [
            "name" => "photo",
            "image_url" =>
            "https://images.unsplash.com/photo-1555400038-63f5ba517a47?w=1000&q=80",
        ],
    ],
  ],
  TRUE
);

$bb->get_image("image uid");

$bb->list_images();

$bb->list_images(10, 25);

$bb->create_video("video template uid", [
  "input_media_url" => "https://www.yourserver.com/videos/awesome_video.mp4",
  "modifications" => [
    [
      "name" => "headline",
      "text" => "Hello world",
    ],
  ],
]);

$bb->get_video("video uid");

$bb->update_video("video uid", [
  "approved" => true,
  "transcription" => [
    "This is a new transcription",
    "It must contain the same number of lines",
    "As the previous transcription",
  ],
]);

$bb->list_videos();

$bb->get_collection("collection uid");
$bb->list_collections(3);
$bb->create_collection(
  "template set uid",
  [
    "modifications" => [
      [
        "name" => "headline",
        "text" => "Hello World!",
      ],
    ],
  ],
  true
);

$bb->get_animated_gif("gif uid")
$bb->list_animated_gifs(3)
$bb->create_animated_gif("template uid", [
    "frames" => [
        [ // frame 1 starts here
            [
                "name" => "layer1",
                "text" => "This is my text"
            ],
            [
                "name" => "photo",
                "image_url" => "https//www.pathtomyphoto.com/1.jpg"
            ]
        ],
        [ // frame 2 starts here
            [
                "name" => "layer1",
                "text" => "This is my follow up text"
            ],
            [
                "name" => "photo",
                "image_url" => "https://www.pathtomyphoto.com/2.jpg"
            ]
        ]
    ]
])

$bb->get_movie("movie uid");
$bb->list_movies(3);
$bb->create_movie([
  "width" => 800,
  "height" => 800,
  "transition" => "pixelize",
  "inputs" => [
    [
      "asset_url" => "https://images.unsplash.com/photo-1635910160061-4b688344bd20?w=500&q=60",
    ],
    [
      "asset_url" => "https://i.imgur.com/fH7a5dO.png",
    ],
  ],
]);

$bb->get_screenshot("screenshot uid");
$bb->list_screenshots(3);
$bb->create_screenshot(
  "https://www.bannerbear.com/",
  [
    "width" => 1000,
  ],
  true
);

$bb->get_template("template uid");
$bb->update_template("template uid", [
  "name" => "New Template Name",
  "tags" => ["portrait", "instagram"],
]);
// Page, Limit, Tag, Name
$bb->list_templates(1, 100, 'tag', 'name');

$bb->get_template_set("template set uid");
$bb->list_template_sets(2);

$bb->get_video_template("video template uid");
$bb->list_video_templates(2);

$bb->generate_signed_url("base uid", [ "modifications" => []]);

// example
$bb->generate_signed_url("A89wavQyY3Bebk3djP", [
    "modifications" => [
        [
            "name" => "country",
            "text" => "testing!",
        ],
        [
            "name" => "photo",
            "image_url" => "https://images.unsplash.com/photo-1638356435991-4c79b00ebef3?w=764&q=80",
        ],
    ],
]);
// => https://ondemand.bannerbear.com/signedurl/A89wavQyY3Bebk3djP/image.jpg?modifications=W3sibmFtZSI6ImNvdW50cnkiLCJ0ZXh0IjoidGVzdGluZyEifSx7Im5hbWUiOiJwaG90byIsImltYWdlX3VybCI6Imh0dHBzOi8vaW1hZ2VzLnVuc3BsYXNoLmNvbS9waG90by0xNjM4MzU2NDM1OTkxLTRjNzliMDBlYmVmMz93PTc2NCZxPTgwIn1d&s=40e7c9d4902b86ea83e0c400e57d7cc580534fd527e234d40a0c7ace589a16eb