<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses('img.io.StreamWriter');

  /**
   * Writes GIF to a stream
   *
   * @ext      gd
   * @see      php://imagegif
   * @see      xp://img.io.StreamWriter
   * @purpose  Writer
   */
  class GifStreamWriter extends StreamWriter {

    /**
     * Output an image
     *
     * @access  protected
     * @param   resource handle
     * @return  bool
     */    
    function output($handle) {
      return imagegif($handle);
    }
  }
?>
<commit_msg>- Convert truecolor images to paletted images before running imagegif() # On my machine, PHP simply segfaults otherwise(!)<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses('img.io.StreamWriter');

  /**
   * Writes GIF to a stream
   *
   * @ext      gd
   * @see      php://imagegif
   * @see      xp://img.io.StreamWriter
   * @purpose  Writer
   */
  class GifStreamWriter extends StreamWriter {
    var
      $dither   = FALSE,
      $ncolors  = 0;

    /**
     * Constructor
     *
     * @see     php://imagetruecolortopalette
     * @access  public
     * @param   &io.Stream stream
     * @param   bool dither default FALSE indicates if the image should be dithered
     * @param   int ncolors default 256 maximum # of colors retained in the palette
     */
    function __construct(&$stream, $dither= FALSE, $ncolors= 256) {
      parent::__construct($stream);
      $this->dither= $dither;
      $this->ncolors= $ncolors;
    }

    /**
     * Output an image. If the image is true-color, it will be converted
     * to a paletted image first using imagetruecolortopalette().
     *
     * @access  protected
     * @param   resource handle
     * @return  bool
     */    
    function output($handle) {
      if (imageistruecolor($handle)) {
        imagetruecolortopalette($handle, $this->dither, $this->ncolors);
      }
      return imagegif($handle);
    }
  }
?>

{'fraction_non_alphanumeric': 0.1185223191380195, 'fraction_numerical': 0.0035915854284248334, 'mean_word_length': 2.150242326332795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6333072', 'n_tokens_mistral': 636, 'n_tokens_neox': 601, 'n_words': 169}