Skip to content

Simple "Play" as film effect #252

@VirtualGit

Description

@VirtualGit

Like Google Photo (and probably others), you may prefer a "Play" button overlay on videos rather than the "film" effect.

I paste here a quick modification of add_movie_frame function that generate such play button instead of the film effect. It's not perfect as two "play" buttons appears overlayed when used with Bootsrap theme and "Photoswipe slideshow" (I didn't test other configurations).

I'm sorry, I have no time to make a PR and improve integration (choice of effect, ...), I just give you the code as is in the hope you will consider it, or maybe it will be usefull for someone.

The result looks like this :

Image

Modified function_frame.php file :

<?php
/***********************************************
* File      :   function_frame.php
* Project   :   piwigo-videojs
* Descr     :   Generate the thumbnail with frame
* Base on   :   Embedded Videos plugin
*
* Created   :   21.06.2013
*
* Copyright 2012-2025 <xbgmsharp@gmail.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
************************************************/

// Check whether we are indeed included by Piwigo.
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');

/**
 * add movie frame to an image (need GD library)
 * @param: string source
 * @param: string destination (if null, the source is modified)
 * @return: void
 */
function add_movie_frame($src, $dest=null)
{
  if (empty($dest))
  {
    $dest = $src;
  }

  // we need gd library
  if (!function_exists('imagecreatetruecolor'))
  {
    if ($dest != $src) copy($src, $dest);
    return;
  }

  // open source image
  switch (strtolower(get_extension($src)))
  {
    case 'jpg':
    case 'jpeg':
      $srcImage = imagecreatefromjpeg($src);
      break;
    case 'png':
      $srcImage = imagecreatefrompng($src);
      break;
    case 'gif':
      $srcImage = imagecreatefromgif($src);
      break;
    default:
      if ($dest != $src) copy($src, $dest);
      return;
  }

  // source properties
  $srcWidth = imagesx($srcImage);
  $srcHeight = imagesy($srcImage);

  // band properties
  $imgBand = imagecreatetruecolor($srcWidth, $srcHeight);

  $black = imagecolorallocate($imgBand, 0, 0, 0);
  $white = imagecolorallocatealpha($imgBand, 245, 245, 245,50);
  $whiteCircle = imagecolorallocatealpha($imgBand, 245, 245, 245,60);

  // add source to band
  imagecopy($imgBand, $srcImage, 0, 0, 0, 0, (int)$srcWidth, (int)$srcHeight);

  $centerX = $srcWidth/2.0;
  $centerY = $srcHeight/2.0;
  $radius = min($srcWidth,$srcHeight)*0.10;
  $points = [];
  for($angle = 0 ; $angle > -2*pi() ; $angle -= 2*pi()/3 )
  {
    array_push($points, $centerX + $radius * cos($angle));
    array_push($points, $centerY + $radius * sin($angle));
  }

  imagefilledpolygon($imgBand, $points, $white);
  imagesetthickness($imgBand, 5);

  cercle_epais($imgBand, $centerX, $centerY, 3*$radius, $radius * 0.8, $whiteCircle);

  // save image
  switch (strtolower(get_extension($dest)))
  {
    case 'jpg':
    case 'jpeg':
      imagejpeg($imgBand, $dest, 85);
      break;
    case 'png':
      imagepng($imgBand, $dest);
      break;
    case 'gif':
      imagegif($imgBand, $dest);
      break;
  }
}

function cercle_epais($image, $cx, $cy, $diametre, $epaisseur, $couleur) {
  for ($i = 0; $i < $epaisseur; $i++) {
      imageellipse($image, (int)$cx, (int)$cy, (int)($diametre - $i), (int)($diametre - $i), $couleur);
  }
}

?>

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions