예제 #1
0
 public function getIcon($id = 0)
 {
     $icon = new floIcon();
     if ($id > 0) {
         $icon->readICO($this->iconpath . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . 'favicon.ico');
     } else {
         $icon->readICO($this->tempicon);
     }
     return $icon;
 }
예제 #2
0
 /**
  * load image
  *
  * @return bool
  * @param string $url source url
  * @param string $extension file extension of output file
  * @param int $width
  * @param int $height
  */
 public function loadImage($url, $extension = 'png', $width = false, $height = false)
 {
     // load image
     try {
         $data = \helpers\WebClient::request($url);
     } catch (\exception $e) {
         \F3::get('logger')->log("failed to retrieve image {$url}," . $e->getMessage(), \ERROR);
         return false;
     }
     // get image type
     $tmp = \F3::get('cache') . '/' . md5($url);
     file_put_contents($tmp, $data);
     $imgInfo = @getimagesize($tmp);
     if (strtolower($imgInfo['mime']) == 'image/vnd.microsoft.icon') {
         $type = 'ico';
     } elseif (strtolower($imgInfo['mime']) == 'image/png') {
         $type = 'png';
     } elseif (strtolower($imgInfo['mime']) == 'image/jpeg') {
         $type = 'jpg';
     } elseif (strtolower($imgInfo['mime']) == 'image/gif') {
         $type = 'gif';
     } elseif (strtolower($imgInfo['mime']) == 'image/x-ms-bmp') {
         $type = 'bmp';
     } else {
         @unlink($tmp);
         return false;
     }
     // convert ico to png
     if ($type == 'ico') {
         $ico = new \floIcon();
         @$ico->readICO($tmp);
         if (count($ico->images) == 0) {
             @unlink($tmp);
             return false;
         }
         ob_start();
         @imagepng($ico->images[count($ico->images) - 1]->getImageResource());
         $data = ob_get_contents();
         ob_end_clean();
     }
     // parse image for saving it later
     @unlink($tmp);
     try {
         $wideImage = \WideImage::load($data);
     } catch (\Exception $e) {
         return false;
     }
     // resize
     if ($width !== false && $height !== false) {
         if ($height !== null && $wideImage->getHeight() > $height || $width !== null && $wideImage->getWidth() > $width) {
             $wideImage = $wideImage->resize($width, $height);
         }
     }
     // return image as jpg or png
     if ($extension == 'jpg') {
         $data = $wideImage->asString('jpg', 75);
     } else {
         $data = $wideImage->asString('png', 4, PNG_NO_FILTER);
     }
     return $data;
 }
예제 #3
0
function colorPalette($imageFile, $numColors, $granularity = 5)
{
    $granularity = max(1, abs((int) $granularity));
    $colors = array();
    $size = @getimagesize($imageFile);
    // to enable .ico support place floIcon.php into lib/
    if (strtolower($size['mime']) == 'image/vnd.microsoft.icon') {
        if (class_exists("floIcon")) {
            $ico = new floIcon();
            @$ico->readICO($imageFile);
            if (count($ico->images) == 0) {
                return false;
            } else {
                $img = @$ico->images[count($ico->images) - 1]->getImageResource();
            }
        } else {
            return false;
        }
    } else {
        if ($size[0] > 0 && $size[1] > 0) {
            $img = @imagecreatefromstring(file_get_contents($imageFile));
        }
    }
    if (!$img) {
        return false;
    }
    for ($x = 0; $x < $size[0]; $x += $granularity) {
        for ($y = 0; $y < $size[1]; $y += $granularity) {
            $thisColor = imagecolorat($img, $x, $y);
            $rgb = imagecolorsforindex($img, $thisColor);
            $red = round(round($rgb['red'] / 0x33) * 0x33);
            $green = round(round($rgb['green'] / 0x33) * 0x33);
            $blue = round(round($rgb['blue'] / 0x33) * 0x33);
            $thisRGB = sprintf('%02X%02X%02X', $red, $green, $blue);
            if (array_key_exists($thisRGB, $colors)) {
                $colors[$thisRGB]++;
            } else {
                $colors[$thisRGB] = 1;
            }
        }
    }
    arsort($colors);
    return array_slice(array_keys($colors), 0, $numColors);
}
예제 #4
0
 /**
  * load local icon file from filesystem as wideimage
  * @return WideImage_TrueColorImage
  * @param string $source of the ico file
  */
 protected function loadIconFileFromFilesystem($source)
 {
     $fileContent = file_get_contents($source);
     $tmp_image = @imagecreatefromstring($fileContent);
     if ($tmp_image !== false) {
         return $tmp_image;
     }
     $ico = new floIcon();
     $ico->readICO($source);
     if (count($ico->images) > 0) {
         return $ico->images[0]->getImageResource();
     }
     return false;
 }
예제 #5
0
 /**
  * load image
  *
  * @return bool
  * @param string $url source url
  * @param int $width
  * @param int $height
  */
 public function loadImage($url, $width = false, $height = false)
 {
     // load image
     $data = @file_get_contents($url);
     if ($data === false) {
         return false;
     }
     // get image type
     $tmp = \F3::get('cache') . '/' . md5($url);
     file_put_contents($tmp, $data);
     $imgInfo = @getimagesize($tmp);
     if (strtolower($imgInfo['mime']) == 'image/vnd.microsoft.icon') {
         $type = 'ico';
     } elseif (strtolower($imgInfo['mime']) == 'image/png') {
         $type = 'png';
     } elseif (strtolower($imgInfo['mime']) == 'image/jpeg') {
         $type = 'jpg';
     } elseif (strtolower($imgInfo['mime']) == 'image/gif') {
         $type = 'gif';
     } elseif (strtolower($imgInfo['mime']) == 'image/x-ms-bmp') {
         $type = 'bmp';
     } else {
         @unlink($tmp);
         return false;
     }
     // convert ico to png
     if ($type == 'ico') {
         $ico = new \floIcon();
         @$ico->readICO($tmp);
         if (count($ico->images) == 0) {
             @unlink($tmp);
             return false;
         }
         ob_start();
         @imagepng($ico->images[count($ico->images) - 1]->getImageResource());
         $data = ob_get_contents();
         ob_end_clean();
     }
     // parse image for saving it later
     @unlink($tmp);
     try {
         $wideImage = \WideImage::load($data);
     } catch (\Exception $e) {
         return false;
     }
     // resize
     if ($width !== false && $height !== false) {
         if ($wideImage->getHeight() > $height || $wideImage->getWidth() > $width) {
             $wideImage = $wideImage->resize($width, $height);
         }
     }
     // return image as png
     $data = $wideImage->asString('png', 0);
     return $data;
 }