composer require borodin-vasiliy/php-stories
// Мы хотим создать 5 секундное сторис размерами 720x1280 $stories = new Stories([ "width" => 720, "height" => 1280, "duration" => 5 ]);
// Путь до файла с котиком $main_image = $dir."/images/1.jpg"; // Получим размеры картинки) list($image_width, $image_height) = getimagesize($main_image); // Посчитаем, каким должно быть приближение для картинки, что бы она покрыла весь сторис $image_start_scale = round(1280 / $image_height, 1); // Добавление картинки $stories->addImage([ "path" => $main_image, "top" => round(-1 * ($image_height * $image_start_scale - $stories_height) / 2), // Вычислим параметр отступа сверху при текущем приближении "left" => round(-1 * ($image_width * $image_start_scale - $stories_width) / 2), // Вычислим параметр отступа слева при текущем приближении "scale" => $image_start_scale ]);
// Путь до файла с котиком $main_image = $dir."/images/1.jpg"; // Получим размеры картинки) list($image_width, $image_height) = getimagesize($main_image); // Посчитаем, каким должно быть приближение для картинки, что бы она покрыла весь сторис $image_start_scale = round(1280 / $image_height, 1); // $image_end_scale = $image_start_scale + 0.5; // Добавление картинки с анимацией $stories->addImage([ "path" => $main_image, "top" => round(-1 * ($image_height * $image_start_scale - $stories_height) / 2), // Вычислим параметр отступа сверху при текущем приближении "left" => round(-1 * ($image_width * $image_start_scale - $stories_width) / 2), // Вычислим параметр отступа слева при текущем приближении "scale" => $image_start_scale ])->addAnimation([ "top" => round(-1 * ($image_height * $image_end_scale - $stories_height) / 2), // Вычислим финальное местоположение картинки с учетом финального приближения "left" => round(-1 * ($image_width * $image_end_scale - $stories_width) / 2),// Вычислим финальное местоположение картинки с учетом финального приближения "scale" => $image_end_scale, ]);
// Добавление заголовка $stories->addText([ "text" => "Hello world!", "path" => $dir."/fonts/helvetica.ttf", "size" => 130, "color" => "#ffffff", "width" => 620, "top" => 200, "left" => 50, "opacity" => 0, "shadow" => [ "color" => "#000000", "top" => 4, "left" => 4 ] ])->addAnimation([ "duration" => 1, "opacity" => 1 ])->addAnimation([ "start" => 4.5, "duration" => 0.5, "opacity" => 0 ]); // Добавление текста $stories->addText([ "text" => "This is a test of function adding text", "path" => $dir."/fonts/helvetica.ttf", "size" => 100, "color" => "#ffffff", "width" => 620, "top" => 750, "left" => 50, "start" => 0.5, "opacity" => 0, "shadow" => [ "color" => "#000000", "top" => 4, "left" => 4 ] ])->addAnimation([ "duration" => 1, "opacity" => 1 ])->addAnimation([ "start" => 4.5, "duration" => 0.5, "opacity" => 0 ]);
$file_hash = $stories->generate("/tmp");
Source: https://habr.com/ru/post/436514/