コード例 #1
0
function image_weight_test($root_folder, $root_list, $image_status_list)
{
    $link = new GrlxLinkStyle();
    $fileops = new GrlxFileOps();
    $allowed_extension = array('gif', 'png', 'jpg', 'svg');
    $overall_status = 0;
    if ($root_list) {
        foreach ($root_list as $key => $val) {
            $folder_list[$root_folder . '/' . $val] = $fileops->get_dir_list($root_folder . '/' . $val);
        }
    }
    if ($folder_list) {
        foreach ($folder_list as $folder => $set) {
            if ($set) {
                foreach ($set as $filename) {
                    $ext = substr($filename, -3, 3);
                    if (in_array($ext, $allowed_extension)) {
                        $image_info = getimagesize($folder . '/' . $filename);
                        $image_bytes = filesize($folder . '/' . $filename);
                        $result = figure_pixel_weight($image_info[0], $image_info[1], $image_bytes);
                        $short = round($result, 3);
                        $status = interpret_image_weight($result);
                        if ($status > $overall_status) {
                            $overall_status = $status;
                        }
                        $pad = $result * 1000;
                        $status = $image_status_list[$status];
                        if (strlen($filename) > 20) {
                            $abbr = substr($filename, 0, 15) . '…';
                        } else {
                            $abbr = $filename;
                        }
                        $image_bytes = number_format($image_bytes);
                        $link->url = "{$folder}/{$filename}";
                        $link->tap = $abbr;
                        $this_link = $link->paint();
                        $output .= <<<EOL
<p>
\t<span style="background:{$status['0']};padding-right:{$pad}px;">&nbsp;</span><br/><strong>{$short} bytes / pixel</strong> <small>({$image_bytes} b / {$image_info['0']} &times; {$image_info['1']} px)</small> {$this_link}
</p>

EOL;
                    }
                }
            }
        }
    }
    return array($output, $overall_status);
}
コード例 #2
0
     $row_divider .= '<hr/>';
 }
 foreach ($page->imageList as $key => $val) {
     $ref_id = $val['image_reference_id'];
     if (count($page->imageList) > 1) {
         $link1->url('book.page-edit.php?page_id=' . $page_id . '&amp;remove_id=' . $key);
         $link1->tap(' Delete this image');
         $link1->title('Permanently delete the graphic from this comic page. There is no undo. Do not pass go. Do not collect 200 cubits.');
         $link1->anchor_class('warning');
         $link1->icon('delete');
         $delete_me = $link1->paint();
     }
     if (is_file('../' . $milieu_list['directory']['value'] . $val['url'])) {
         $image_dimensions = getimagesize('../' . $milieu_list['directory']['value'] . $val['url']);
         $image_bytes = filesize('../' . $milieu_list['directory']['value'] . $val['url']);
         $weight = figure_pixel_weight($image_dimensions[0], $image_dimensions[1], $image_bytes);
     } else {
         $weight = 0;
     }
     $weight = round($weight, 3);
     !$milieu_list['directory']['value'] || $milieu_list['directory']['value'] == '' ? $url_prefix = '../' : ($url_prefix = '../');
     $this_image = '<img src="' . $url_prefix . $milieu_list['directory']['value'] . $val['url'] . '" alt="' . $val['description'] . '"/>' . "\n";
     $link1->title = 'Learn more about pixel weight';
     $link1->url = 'http://getgrawlix.com/docs/' . DOCS_VERSION . '/image-optimization';
     $link1->tap = 'bytes/pixel';
     $this_description = '<p><label for="image_description[' . $val['image_reference_id'] . ']">Description (alt text)</label>' . "\n";
     $this_description .= '<input type="text" name="image_description[' . $val['image_reference_id'] . ']" id="image_description[' . $val['image_reference_id'] . ']" value="' . $val['description'] . '" style="max-width:20rem"/><br/>' . "\n";
     $this_weight .= 'Weight: ' . $weight . ' ' . $link1->paint() . '</p>' . "\n";
     $temp_path = explode('/', $val['url']);
     array_pop($temp_path);
     $temp_path = implode('/', $temp_path);