Ignore:
Timestamp:
May 7, 2010, 10:23:47 PM (14 years ago)
Author:
grum
Message:

Plugin is now in a usable state (color analysis is not yet tuned)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/ColorStat/cstat_root.class.inc.php

    r5961 r6107  
    1313
    1414  --------------------------------------------------------------------------- */
     15
     16  if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     17
     18
    1519  include_once('cstat_colorstat.class.inc.php');
    1620  include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php');
     
    6367      $this->config=array(
    6468        'newInstall' => 'n',
    65         'analyze.maxTime' => 0.1,
    66         'analyze.colorTable' => 'small',
    67         'analyze.pps' => 0,
    68         'analyze.itemPerRequest' => 10,
    69         'display.stat.orderType' => 'img',
     69        'analyze_maxTime' => 0.1,
     70        'analyze_colorTable' => 'small',
     71        'analyze_pps' => 0,
     72        'analyze_itemPerRequest' => 10,
     73        'display_gallery_showColors' => 'n',
     74        'display_stat_orderType' => 'img',
     75        'stat_minPct' => 3.5,
    7076      );
    7177    }
     
    137143     * @return String : HTML code
    138144     */
    139     public function htmlColorList($colorList, $split=8, $size=5, $id="", $class="")
     145    public function htmlColorList($colorList, $split=8, $size=5, $id="", $class="", $br='<br>')
    140146    {
    141147      global $template;
     
    163169        'size' => $size,
    164170        'id' => $id,
    165         'class' => $class
     171        'class' => $class,
     172        'br' => $br,
    166173      );
    167174
     
    172179    }
    173180
    174 
    175 
    176 
    177     protected function displayResult($action_msg, $result)
    178     {
    179       global $page;
    180 
     181    /**
     182     * returns an array of colors & colors percent of an image
     183     *
     184     * @param Integer $imageId : id of the image
     185     * @return Array('colors' => Array(), 'colors_pct' => Array())
     186     */
     187    public function getImageColors($imageId)
     188    {
     189      $returned=Array(
     190        'colors' => Array(),
     191        'colors_pct' => Array(),
     192      );
     193
     194      $sql="SELECT colors, colors_pct
     195            FROM ".$this->tables['images']."
     196            WHERE image_id='".$imageId."'";
     197      $result=pwg_query($sql);
    181198      if($result)
    182199      {
    183         array_push($page['infos'], $action_msg);
    184       }
    185       else
    186       {
    187         array_push($page['errors'], $action_msg);
    188       }
    189     }
     200        while($row=pwg_db_fetch_assoc($result))
     201        {
     202          $returned['colors']=explode(',', $row['colors']);
     203          $returned['colors_pct']=explode(',', $row['colors_pct']);
     204        }
     205      }
     206      return($returned);
     207    }
     208
     209
     210
     211    /**
     212     *  return all HTML&JS code necessary to display a dialogbox to choose
     213     *  colors
     214     */
     215    protected function dialogBoxColor()
     216    {
     217      global $template;
     218
     219      $template->set_filename('colors_choose',
     220                    dirname($this->getFileLocation()).'/templates/cstat_dialog_colors_choose.tpl');
     221
     222      $colorTable=$this->getColorTableWithStat();
     223
     224      $datas=Array(
     225        'colorTable' => $this->htmlColorTable(
     226                          $colorTable,
     227                          ($this->config['analyze_colorTable']=='small')?16:8,
     228                          "",
     229                          "color0px"
     230                        ),
     231        //'urlRequest' => $this->getAdminLink(),
     232      );
     233
     234      $template->assign('datas', $datas);
     235      unset($data);
     236
     237      return($template->parse('colors_choose', true));
     238    }
     239
     240
     241    /**
     242     * return a color table with stat on color
     243     *
     244     * @return Array : a color table with statistics on colors
     245     */
     246    protected function getColorTableWithStat()
     247    {
     248      $generalStats=$this->getGeneralStats();
     249
     250      $colors=Array();
     251      $sql="SELECT color_id, num_images, num_pixels
     252            FROM ".$this->tables['color_table']."
     253            WHERE num_images > 0
     254            ORDER BY color_id ";
     255      $result=pwg_query($sql);
     256      if($result)
     257      {
     258        while($row=pwg_db_fetch_assoc($result))
     259        {
     260          $colors[$row['color_id']]=Array('num_images' => $row['num_images'], 'num_pixels' => $row['num_pixels']);
     261        }
     262      }
     263
     264      $colorTable=ColorStat::getColorTable(
     265        $this->colorTableSize[$this->config['analyze_colorTable']][0],
     266        $this->colorTableSize[$this->config['analyze_colorTable']][1]
     267      );
     268      foreach($colorTable as $key=>$val)
     269      {
     270        foreach($val as $key2=>$val2)
     271        {
     272          $rgb=$val2->getRGB()->getHexString();
     273          $colorTable[$key][$key2]=Array(
     274            'color' => $rgb,
     275            'pct'   => '', //(array_key_exists($rgb, $colors))?sprintf("%.2f", round(100*$colors[$rgb]['num_pixels']/$generalStats['pixelsAnalyzedSum'],2)):"",
     276            'num'   => (array_key_exists($rgb, $colors))?$colors[$rgb]['num_images']:"",
     277          );
     278        }
     279      }
     280
     281      unset($colors);
     282      return($colorTable);
     283    }
     284
     285
     286
    190287
    191288
Note: See TracChangeset for help on using the changeset viewer.