Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- $magick_commands = array ('gm convert', 'convert');
- $image_rendition_geometries = array(
- '138',
- '240',
- '400',
- '507',
- '800',
- '1034',
- '1200',
- '1600',
- '2000'
- );
- // Make sure you have input.png
- $input_file = 'input.png';
- // Since GraphicsMagick and ImageMagick accepts the same parameters, just iterate
- // over the commands and concatenate with the same paramters.
- foreach ($magick_commands as $magick_command)
- {
- $start = getTime();
- // Iterate through the process several times to get a good average
- for ($i = 1; $i <= 10; $i++)
- {
- // Iterate over the defined geometries. Having multiple geometries
- // allows assement of average performance at different geometries
- foreach ($image_rendition_geometries as $image_rendition_geometry)
- {
- // Create output filename like this: 'gm convert-138.png', 'convert-2000.png', etc.
- $output_file = "'$magick_command-$image_rendition_geometry" . ".png'";
- // Execute magick command
- $command = "$magick_command -units PixelsPerInch -density 96x96 -quality 100 -resize " . $image_rendition_geometry . "x $input_file $output_file";
- exec($command);
- }
- }
- $end = getTime();
- $time_difference = round($end - $start, 4);
- $iteration = $i - 1;
- echo ("'$magick_command' took $time_difference seconds to execute $iteration iteration(s). <br/>");
- }
- // Get filesize of the generated images
- reset($magick_commands);
- $file_sizes = array();
- foreach ($magick_commands as $magick_command)
- {
- reset($image_rendition_geometries);
- foreach ($image_rendition_geometries as $image_rendition_geometry)
- {
- $output_file = "$magick_command-$image_rendition_geometry" . ".png";
- $file_sizes[$magick_command][$image_rendition_geometry] = filesize($output_file);
- }
- }
- // Display the average file sizes
- reset($magick_commands);
- foreach ($magick_commands as $magick_command)
- {
- print_r("Average filesize of $magick_command: " . number_format(array_sum($file_sizes[$magick_command]) / count($image_rendition_geometries), 0, '', ',') . ' bytes. <br/>');
- }
- function getTime() {
- $timer = explode( ' ', microtime() );
- $timer = $timer[1] + $timer[0];
- return $timer;
- }
Advertisement
Add Comment
Please, Sign In to add comment