private static function createComparisonPalette() { if (self::$comp_palette === false) { $swatch_index = array(); self::$comp_palette = imagecreate(16, 16); foreach (self::$swatches as $name => $hex) { $color = self::hexToRGB($hex); $index = imagecolorallocate(self::$comp_palette, $color['red'], $color['green'], $color['blue']); self::$swatch_index[$index] = $name; } } }
public function parseColor() { $viewer = Engine_Api::_()->user()->getViewer(); if ($viewer->getIdentity()) { $timezone = $viewer->timezone; } else { $timezone = date_default_timezone_get(); } date_default_timezone_set($timezone); $colorTbl = Engine_Api::_()->getDbTable("colors", "advalbum"); Advalbum_Libs_ColorCompare::$swatches = $colorTbl->getColorArray(); $filename = $this->getPhotoUrl(); /* $file = Engine_Api::_()->getApi('storage', 'storage')->get($this->file_id, null); $filepath = $file->storage_path; */ $tmpRow = Engine_Api::_()->getItem('storage_file', $this->file_id); $filepath = $tmpRow->temporary(); $max_colors = Engine_Api::_()->getApi('settings', 'core')->getSetting('advalbum.maxcolor', 1); $result = Advalbum_Libs_ColorCompare::compare($max_colors, $filepath); if ($result == false) { return false; } else { $colorIds = $colorTbl->getColorIds(); $photoColorTbl = Engine_Api::_()->getDbTable("photocolors", "advalbum"); foreach ($result as $color => $count) { $photocolor = $photoColorTbl->createRow(); $photocolor->photo_id = $this->getIdentity(); $photocolor->color_title = $color; $photocolor->pixel_count = $count; $photocolor->save(); } } @unlink($filepath); }