Brug af AI afslører de svagheder, virksomheder allerede har opbygget gennem års cloud-transformation, nye SaaS-løsninger og fragmenterede sikkerhedssystemer.
Det kan du naturligvis godt have ret i. Så jeg vover pelsen og smider hele koden :-)
<?php // // Class to render array as image //
/** * * Class array_to_image: show a bidimensional array as an image representing * a table. Allows: * - set max image size and automatly resize if the resulting image is to big * - different background and text color for head and rows * - alternate background abd text color for even and odd rows * - PNG or JPG format * - store to files or show directly * * @author Roberto 'Frank' Franchini <f.rank@libero.it> * @version 1.1 * */
class array_to_image { /** * Array to be showed * @var array * @access public */ var $arr; /** * Image handle * @var handler * @access private */ var $image; /** * Fonts and colors parameters * @var font * @access private */ var $font; var $fontWidth; var $even_bgcolor; var $even_txt_color; var $odd_bgcolor; var $odd_txt_color; var $head_bgcolor; var $head_txt_color; var $line_color; //options var $cellspacing; var $center; //if true center the text var $max_x; //max dimension var $max_y; var $type; //private parameters (calculated) var $rows; //number of rows and columns var $cols; var $dim_x; //width and height in pixel of the resulting image var $dim_y; var $row_height; //height of each row in pixel //it's all OK? var $flag;
/** * Show or store to the given file name the image * in the selected format. It calls _image_create() if * the handle isn't setted, and then calls _draw_table() * that draws the table on the handle. * * @param string $name name of file where to store the image * @param bool $destroy tells if the image handle should be destoyed * @access public * @returns image png or jpg image if $name is setted */ function show_image($nome='', $destroy=true) { if (!$this->image) { $this->_create_image(); } $this->_draw_table(); switch ($this->type) { case 'png': if ($nome) { imagepng($this->image,$nome.".png"); } else { header("Content-type: image/png"); imagepng($this->image); } break; case 'jpeg': if ($nome) { imagejpeg ($this->image,$nome.".jpg"); } else { header ("Content-type: image/jpeg"); imagejpeg ($this->image); } break; } if ($destroy == true) { $this->_array_to_image(); imagedestroy($this->image); } } //end func show_image
/** * Create an associative array for color values * * @param sting $color comma separated value for Red,Green,Blue * @access private * @returns associative arrary of colors */ function _setcolor($color) { $color = explode(",",$color); $red = $color[0]; $green = $color[1]; $blue = $color[2]; return (array(red=>$red,green=>$green,blue=>$blue)); }
/** * Create the image and if necesary resize it to fit the * max dimension required. This method only allocates graphic space * where to draw the table * * @access private * @returns none */
function _create_image() { if ((!$this->cols) || (!$this->rows)) $this->_max_cells_width(); if ((!$this->dim_x) || (!$this->dim_y)) $this->_image_dimension(); //if calculated dimension of resulting image are bigger than // max dimension, drop down font dimension and cellspacing while (($this->dim_x > $this->max_x) or ($this->dim_y > $this->max_y) and ($this->font > 1 or $this->cellspacing > 1 )) { $this->cellspacing = ($this->cellspacing > 1) ? $this->cellspacing-1 : 1; $this->font = ($this->font > 1) ? $this->font-1 : 1; $this->_max_cells_width(); $this->_image_dimension(); } //now i can create the image $this->image = imagecreate($this->dim_x, $this->dim_y); $this->_set_cells_color(); } //end func _create_image
/** * Draw the table as image. Doesn't show any output. * * @access private * @returns none */
/** * Claculate the pixel lenght and widht of resulting image * and set the parameters dim_x and dim_y * * @access private * @return bool */ function _image_dimension() { $this->fontWidth = imagefontwidth($this->font); $font_height = imagefontheight($this->font); $tot_char_width = 0; //total width of array in character if (($this->cols == 0) || ($this->rows == 0)) { $this->_max_cells_width(); } reset($this->arr); while (list($i,$num_char) = each($this->arr['width'])) { $tot_char_width += $num_char; } $this->row_height = $font_height + 2 * $this->cellspacing ; //resulting image's dimension in pixel $this->dim_x = $tot_char_width * $this->fontWidth + $this->cols * 2 * $this->cellspacing + 1; $this->dim_y = ($this->rows-1) * ($this->row_height) + 1; return($this->flag); }
/** * Calculate the maximun width as number of character * for each column of the original bidimensional array * It adds a row to the array : * $this->array[width] = array(); * and then sets the parameters $rows, $cols * * @access private * @returns void */ function _max_cells_width() { $this->arr['width'] = array(); $this->rows = 0; $this->cols = 0; reset($this->arr); while (list($row_key,$row) = each($this->arr)) { while (list($col_key,$elem) = each($row)) { $width = strlen($elem); if (($this->arr['width'][$col_key] < $width) and ($row_key != 'width')) { $this->arr['width'][$col_key] = $width; } } $this->rows++; } $this->cols = count($this->arr['width']); }//end func _max_cells_width
} //end of class array_to_image
?>
Synes godt om
Slettet bruger
13. februar 2004 - 15:58#3
Hvis du lod være med at undretrykke alle errors ville der nok komme noget, istedet for bare blank html..
ja, det gør det, men den gør ikke det jeg vil have den til, så jeg er gået i krig med et andet kode eksempel. Jeg skal have lavet et søjle eller cirkel-diagram ud fra et db-udtræk.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.