/** * Transforms an image in video clip * @global string $ffmpegpath * @global type $encoders_path * @param type $movieout * @param type $imagein * @param string $encoder * @param type $duration * @return boolean */ function movie_title_from_image($movieout, $imagein, $encoder, $duration = 8) { global $ffmpegpath, $encoders_path, $aac_experimental; $movieout = escape_path($movieout); $encoder_values = explode('_', $encoder); $codec = $encoder_values[0]; $quality = $encoder_values[1]; $resolution_values = explode('x', $encoder_values[2]); $width = $resolution_values[0]; $height = $resolution_values[1]; $encoder = $encoders_path . '/' . $codec . '_' . $quality . '.ffpreset'; // checks if the encoder file exists if (!is_file($encoder)) { return "encoder not found {$encoder}"; } $video_filter = "scale=iw*min({$width}/iw\\,{$height}/ih):ih*min({$width}/iw\\,{$height}/ih), pad={$width}:{$height}:({$width}-iw*min({$width}/iw\\,{$height}/ih))/2:({$height}-ih*min({$width}/iw\\,{$height}/ih))/2"; if ($aac_experimental) { $aac_codec = ' -acodec aac -strict experimental '; // overwrites audio codec from encoders file } /* * generates input silent audio stream for titling: * -ar : audio sample rate * -ac : audio channels * -f : force audio input format (s161e required to generate the audio stream) * -t : duration in seconds * -i : input source * generates input video stream for titling : * -loop : better image rendering * -r : frame rate * -i : input file (image) for title * -t : duration in secondes * -fpre : video preset file (settings used to encode the video) */ $cmd = $ffmpegpath . ' -ar 44100 -ac 2 -f s16le -t ' . $duration . ' -i /dev/zero ' . '-loop 1 -r 25 -i ' . $imagein . ' -t ' . $duration . ' -vf "' . $video_filter . '" -fpre ' . $encoder . ' ' . $aac_codec . ' -y ' . $movieout; exec($cmd, $cmdoutput, $returncode); print "\n{$cmd}\n"; //check returncode if ($returncode) { return join("\n", $cmdoutput); } return false; }
function gd_image_create($title_array, $width, $height, $file) { global $fontfile; global $quality; global $fontratio; global $linelength; // creates the image $img = imagecreate($width, $height); // defines the background color $bg_color = imagecolorallocate($img, 8, 89, 155); // setup the text color $txt_color['white'] = imagecolorallocate($img, 255, 255, 255); $txt_color['blue'] = imagecolorallocate($img, 105, 139, 205); if (isset($title_array['album'])) { // font size relative to the global height of the image $fontsize = $height / (32 * $fontratio); // gd_push_text($img, $fontsize, $txt_color['blue'], wordwrap($title_array['album'], 45,"\n"), ($height * 0.25)); $dimensions = imagettfbbox($fontsize, 0, $fontfile, $title_array['album']); $txt_height = $dimensions[1] - $dimensions[7]; // splits the string in multiple strings if its size is too long $album = split_title($title_array['album'], $linelength * 1.27); switch (count($album)) { case 1: $pct_height = 0.25; break; case 2: $pct_height = 0.2; break; case 3: $pct_height = 0.15; break; default: $pct_height = 0.25; break; } // adds each value of the array in the generated image foreach ($album as $index => $string) { gd_push_text($img, $fontsize, $txt_color['blue'], $string, $height * $pct_height + $index * ($txt_height + 5)); } } if (isset($title_array['title'])) { $fontsize = $height / (25 * $fontratio); $dimensions = imagettfbbox($fontsize, 0, $fontfile, $title_array['title']); $txt_height = $dimensions[1] - $dimensions[7]; // splits the string in multiple strings if its size is too long $title = split_title($title_array['title'], $linelength); // adds each value of the array in the generated image foreach ($title as $index => $string) { gd_push_text($img, $fontsize, $txt_color['white'], $string, $height * 0.4 + $index * ($txt_height + 5)); } } if (isset($title_array['author'])) { $fontsize = $height / (32 * $fontratio); gd_push_text($img, $fontsize, $txt_color['white'], $title_array['author'], $height * 0.7); } if (isset($title_array['date']) && $title_array['hide_date'] != true) { $fontsize = $height / (42 * $fontratio); gd_push_text($img, $fontsize, $txt_color['white'], $title_array['date'], $height * 0.75); } if (isset($title_array['copyright']) || isset($title_array['organization'])) { $string = $title_array['copyright'] . (isset($title_array['copyright']) && isset($title_array['organization']) ? " - " : "") . $title_array['organization']; $fontsize = $height / (55 * $fontratio); gd_push_text($img, $fontsize, $txt_color['blue'], escape_path($string), $height * 0.95); } // generates the image return imagejpeg($img, $file, $quality); }