Beispiel #1
0
 /**
  * this is to force RGB and to apply custom icc color profiles
  */
 protected function applyColorProfiles()
 {
     if ($this->resource->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
         if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
             $profiles = $this->resource->getImageProfiles('*', false);
             // we're only interested if ICC profile(s) exist
             $has_icc_profile = array_search('icc', $profiles) !== false;
             // if it doesn't have a CMYK ICC profile, we add one
             if ($has_icc_profile === false) {
                 $this->resource->profileImage('icc', self::getCMYKColorProfile());
             }
             // then we add an RGB profile
             $this->resource->profileImage('icc', self::getRGBColorProfile());
             $this->resource->setImageColorspace(Imagick::COLORSPACE_RGB);
         }
     }
     // this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
     // thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
     // problem is described here: http://imagemagick.org/Usage/basics/#type
     // and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
     if ($this->resource->getimagetype() == Imagick::IMGTYPE_GRAYSCALE) {
         $draw = new ImagickDraw();
         $draw->setFillColor("red");
         $draw->setfillopacity(0.001);
         $draw->point(0, 0);
         $this->resource->drawImage($draw);
     }
 }
 public function makeThumb($path, $W = NULL, $H = NULL)
 {
     $image = new Imagick();
     $image->readImage($ImgSrc);
     // Trasformo in RGB solo se e` il CMYK
     if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
         $image->transformImageColorspace(Imagick::COLORSPACE_RGB);
     }
     $image->profileImage('*', NULL);
     $image->stripImage();
     $imgWidth = $image->getImageWidth();
     $imgHeight = $image->getImageHeight();
     if ((!$H || $H == null || $H == 0) && (!$W || $W == null || $W == 0)) {
         $W = $imgWidth;
         $H = $imgHeight;
     } elseif (!$H || $H == null || $H == 0) {
         $H = $W * $imgHeight / $imgWidth;
     } elseif (!$W || $W == null || $W == 0) {
         $W = $H * $imgWidth / $imgHeight;
     }
     $image->resizeImage($W, $H, Imagick::FILTER_LANCZOS, 1);
     /** Scrivo l'immagine */
     $image->writeImage($path);
     /** IMAGE OUT */
     header('X-MHZ-FLY: Nice job!');
     header(sprintf('Content-type: image/%s', strtolower($image->getImageFormat())));
     echo $image->getImageBlob();
     $image->destroy();
     die;
 }
Beispiel #3
0
 public function overlay($layer, $x = 0, $y = 0)
 {
     $layerCs = $layer->image->getImageColorspace();
     $layer->image->setImageColorspace($this->image->getImageColorspace());
     $this->image->compositeImage($layer->image(), $this->compositionMode, $x, $y);
     $layer->image->setImageColorspace($layerCs);
     return $this;
 }
Beispiel #4
0
 /**
  * @return $this
  */
 public function setColorspaceToRGB()
 {
     $imageColorspace = $this->resource->getImageColorspace();
     if ($imageColorspace == \Imagick::COLORSPACE_CMYK) {
         if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
             $profiles = $this->resource->getImageProfiles('*', false);
             // we're only interested if ICC profile(s) exist
             $has_icc_profile = array_search('icc', $profiles) !== false;
             // if it doesn't have a CMYK ICC profile, we add one
             if ($has_icc_profile === false) {
                 $this->resource->profileImage('icc', self::getCMYKColorProfile());
             }
             // then we add an RGB profile
             $this->resource->profileImage('icc', self::getRGBColorProfile());
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
             // we have to use SRGB here, no clue why but it works
         } else {
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
         }
     } else {
         if ($imageColorspace == \Imagick::COLORSPACE_GRAY) {
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
         } else {
             if (!in_array($imageColorspace, array(\Imagick::COLORSPACE_RGB, \Imagick::COLORSPACE_SRGB))) {
                 $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
             } else {
                 // this is to handle embedded icc profiles in the RGB/sRGB colorspace
                 $profiles = $this->resource->getImageProfiles('*', false);
                 $has_icc_profile = array_search('icc', $profiles) !== false;
                 if ($has_icc_profile) {
                     try {
                         // if getImageColorspace() says SRGB but the embedded icc profile is CMYK profileImage() will throw an exception
                         $this->resource->profileImage('icc', self::getRGBColorProfile());
                     } catch (\Exception $e) {
                         \Logger::warn($e);
                     }
                 }
             }
         }
     }
     // this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
     // thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
     // problem is described here: http://imagemagick.org/Usage/basics/#type
     // and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
     $currentLocale = setlocale(LC_ALL, "0");
     // this locale hack thing is also a hack for imagick
     setlocale(LC_ALL, "");
     // details see https://www.pimcore.org/issues/browse/PIMCORE-2728
     $draw = new \ImagickDraw();
     $draw->setFillColor("#ff0000");
     $draw->setfillopacity(0.01);
     $draw->point(floor($this->getWidth() / 2), floor($this->getHeight() / 2));
     // place it in the middle of the image
     $this->resource->drawImage($draw);
     setlocale(LC_ALL, $currentLocale);
     // see setlocale() above, for details ;-)
     return $this;
 }
Beispiel #5
0
 /**
  * Constructor of the class
  *
  * @param \Imagick $image The Imagick instance
  */
 public function __construct(\Imagick $image)
 {
     //Convert CMYK to RGB
     if ($image->getImageColorspace() === \Imagick::COLORSPACE_CMYK) {
         $profiles = $image->getImageProfiles('*', false);
         if (array_search('icc', $profiles) === false) {
             $image->profileImage('icc', file_get_contents(__DIR__ . '/icc/us_web_uncoated.icc'));
         }
         $image->profileImage('icm', file_get_contents(__DIR__ . '/icc/srgb.icm'));
         $image->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
     }
     $this->image = $image;
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function getColorSpace()
 {
     switch ($this->imagick->getImageColorspace()) {
         case \Imagick::COLORSPACE_RGB:
         case \Imagick::COLORSPACE_SRGB:
             return ColorSpace::COLOR_SPACE_RGB;
         case \Imagick::COLORSPACE_CMYK:
             return ColorSpace::COLOR_SPACE_CMYK;
         case \Imagick::COLORSPACE_GRAY:
             return ColorSpace::COLOR_SPACE_GRAYSCALE;
         default:
             throw new RuntimeException('Only RGB, grayscale and CMYK color space are currently supported');
     }
 }
Beispiel #7
0
 /**
  * @return $this
  */
 public function setColorspaceToRGB()
 {
     $imageColorspace = $this->resource->getImageColorspace();
     if ($imageColorspace == \Imagick::COLORSPACE_CMYK) {
         if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
             $profiles = $this->resource->getImageProfiles('*', false);
             // we're only interested if ICC profile(s) exist
             $has_icc_profile = array_search('icc', $profiles) !== false;
             // if it doesn't have a CMYK ICC profile, we add one
             if ($has_icc_profile === false) {
                 $this->resource->profileImage('icc', self::getCMYKColorProfile());
             }
             // then we add an RGB profile
             $this->resource->profileImage('icc', self::getRGBColorProfile());
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
             // we have to use SRGB here, no clue why but it works
         } else {
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
         }
     } else {
         if ($imageColorspace == \Imagick::COLORSPACE_GRAY) {
             $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
         } else {
             if (!in_array($imageColorspace, array(\Imagick::COLORSPACE_RGB, \Imagick::COLORSPACE_SRGB))) {
                 $this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
             } else {
                 // this is to handle embedded icc profiles in the RGB/sRGB colorspace
                 $profiles = $this->resource->getImageProfiles('*', false);
                 $has_icc_profile = array_search('icc', $profiles) !== false;
                 if ($has_icc_profile) {
                     $this->resource->profileImage('icc', self::getRGBColorProfile());
                 }
             }
         }
     }
     // this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
     // thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
     // problem is described here: http://imagemagick.org/Usage/basics/#type
     // and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
     $draw = new \ImagickDraw();
     $draw->setFillColor("#ff0000");
     $draw->setfillopacity(0.01);
     $draw->point(floor($this->getWidth() / 2), floor($this->getHeight() / 2));
     // place it in the middle of the image
     $this->resource->drawImage($draw);
     return $this;
 }
Beispiel #8
0
 public function overlay($layer, $x = 0, $y = 0)
 {
     //$layer_cs = $layer->image->getImageColorspace();
     $layer->image->setImageColorspace($this->image->getImageColorspace());
     if ($this->multiframe()) {
         $this->image = $this->image->coalesceImages();
         $width = $this->image->getImageWidth();
         $height = $this->image->getImageHeight();
         foreach ($this->image as $frame) {
             $over = clone $layer->image;
             $frame->setImagePage($width, $height, 0, 0);
             $frame->compositeImage($over, $this->composition_mode, $x, $y);
         }
         // It's magic but it work
         $this->image->getImagesBlob();
         $this->image->deconstructImages();
     } else {
         $this->image->compositeImage($layer->image, $this->composition_mode, $x, $y);
     }
     //$layer->image->setImageColorspace($layer_cs);
     return $this;
 }
Beispiel #9
0
} else {
    Logger::debug('main', '(client/applications) No Session id nor public_webservices_access');
    echo return_error(7, 'No Session id nor public_webservices_access');
    die;
}
$applicationDB = ApplicationDB::getInstance();
$applications = $applicationDB->getApplicationsWithMimetype($_GET['id']);
$apps = array();
foreach ($applications as $application) {
    if (!$application->haveIcon()) {
        continue;
    }
    $score = count($application->groups());
    if ($application->getAttribute('type') == 'windows') {
        $score += 10;
    }
    $apps[$score] = $application;
}
header('Content-Type: image/png');
$first = new Imagick(realpath(dirname(__FILE__) . '/../admin/media/image/empty.png'));
if (!is_array($apps) || count($apps) == 0) {
    echo $first;
    die;
}
arsort($apps);
$application = array_shift($apps);
$second = new Imagick(realpath($application->getIconPath()));
$second->scaleImage(16, 16);
$first->setImageColorspace($second->getImageColorspace());
$first->compositeImage($second, $second->getImageCompose(), 6, 10);
echo $first;
Beispiel #10
0
 /**
  * Returns the palette corresponding to an Imagick resource colorspace
  *
  * @param Imagick $imagick
  *
  * @return CMYK|Grayscale|RGB
  *
  * @throws NotSupportedException
  */
 private function createPalette(Imagick $imagick)
 {
     switch ($imagick->getImageColorspace()) {
         case Imagick::COLORSPACE_RGB:
         case Imagick::COLORSPACE_SRGB:
             return new RGB();
         case Imagick::COLORSPACE_CMYK:
             return new CMYK();
         case Imagick::COLORSPACE_GRAY:
             return new Grayscale();
         default:
             throw new NotSupportedException('Only RGB and CMYK colorspace are currently supported');
     }
 }
Beispiel #11
0
 /**
  * Takes an image filename and returns an Imagick image object
  *
  * @param string $imgfile the full path and filename of the image to load
  * @return Imagick
  */
 function zp_imageGet($imgfile)
 {
     global $_lib_Imagick_info;
     if (array_key_exists(strtoupper(getSuffix($imgfile)), $_lib_Imagick_info)) {
         $image = new Imagick();
         $maxHeight = getOption('magick_max_height');
         $maxWidth = getOption('magick_max_width');
         if ($maxHeight > lib_Imagick_Options::$ignore_size && $maxWidth > lib_Imagick_Options::$ignore_size) {
             $image->setOption('jpeg:size', $maxWidth . 'x' . $maxHeight);
         }
         $image->readImage(imgSrcURI($imgfile));
         //Generic CMYK to RGB conversion
         if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
             $image->transformimagecolorspace(Imagick::COLORSPACE_SRGB);
         }
         return $image;
     }
     return false;
 }
Beispiel #12
0
    $imgOut = sprintf('spool/%s_w%s_%sx.%s', $matches[1], $matches[2], $M, $matches[3]);
    $W = $matches[2];
    $H = null;
    if (!file_exists($imgSrc)) {
        include 'error404.php';
        return;
    }
} else {
    return;
}
// Moltiplico la dimensione
$W = $W * $M;
$image = new Imagick();
$image->readImage($imgSrc);
// Trasformo in RGB solo se e` il CMYK
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
    $image->transformImageColorspace(Imagick::COLORSPACE_RGB);
}
$image->profileImage('*', NULL);
$image->stripImage();
$imgWidth = $image->getImageWidth();
$imgHeight = $image->getImageHeight();
if ((!$H || $H == null || $H == 0) && (!$W || $W == null || $W == 0)) {
    $W = $imgWidth;
    $H = $imgHeight;
} elseif (!$H || $H == null || $H == 0) {
    $H = $W * $imgHeight / $imgWidth;
} elseif (!$W || $W == null || $W == 0) {
    $W = $H * $imgWidth / $imgHeight;
}
$image->resizeImage($W, $H, Imagick::FILTER_LANCZOS, 1);
}
//calculate the position from the source image if we need to crop and where
//we need to put into the target image.
$dst_x = $src_x = $dst_y = $src_y = 0;
if ($_POST["imageX"] > 0) {
    $dst_x = abs($_POST["imageX"]);
} else {
    $src_x = abs($_POST["imageX"]);
}
if ($_POST["imageY"] > 0) {
    $dst_y = abs($_POST["imageY"]);
} else {
    $src_y = abs($_POST["imageY"]);
}
//This fix the page of the image so it crops fine!
$img->setimagepage(0, 0, 0, 0);
//crop the image with the viewed into the viewport
$img->cropImage($viewPortW, $viewPortH, $src_x, $src_y);
//create the viewport to put the cropped image
$viewport = new Imagick();
$viewport->newImage($viewPortW, $viewPortH, '#' . $colorHEX);
$viewport->setImageFormat($ext);
$viewport->setImageColorspace($img->getImageColorspace());
$viewport->compositeImage($img, $img->getImageCompose(), $dst_x, $dst_y);
//crop the selection from the viewport
$viewport->setImagePage(0, 0, 0, 0);
$viewport->cropImage($_POST["selectorW"], $_POST["selectorH"], $selectorX, $selectorY);
$targetFile = 'tmp/test_' . time() . "." . $ext;
//save the image into the disk
$viewport->writeImage($targetFile);
echo $targetFile;
Beispiel #14
0
 public function convert2sRGBColorSpace($src, $dir, $cache, $iccFile, $useCache = true)
 {
     if ($this->verbose) {
         $this->log("# Converting image to sRGB colorspace.");
     }
     if (!class_exists("Imagick")) {
         $this->log(" Ignoring since Imagemagick is not installed.");
         return false;
     }
     $this->setSaveFolder($cache)->setSource($src, $dir)->generateFilename(null, false, 'srgb_');
     if ($useCache && is_readable($this->cacheFileName)) {
         $fileTime = filemtime($this->pathToImage);
         $cacheTime = filemtime($this->cacheFileName);
         if ($fileTime <= $cacheTime) {
             $this->log(" Using cached version: " . $this->cacheFileName);
             return $this->cacheFileName;
         }
     }
     if (is_writable($this->saveFolder)) {
         $image = new Imagick($this->pathToImage);
         $colorspace = $image->getImageColorspace();
         $this->log(" Current colorspace: " . $colorspace);
         $profiles = $image->getImageProfiles('*', false);
         $hasICCProfile = array_search('icc', $profiles) !== false;
         $this->log(" Has ICC color profile: " . ($hasICCProfile ? "YES" : "NO"));
         if ($colorspace != Imagick::COLORSPACE_SRGB || $hasICCProfile) {
             $this->log(" Converting to sRGB.");
             $sRGBicc = file_get_contents($iccFile);
             $image->profileImage('icc', $sRGBicc);
             $image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
             $image->writeImage($this->cacheFileName);
             return $this->cacheFileName;
         }
     }
     return false;
 }
Beispiel #15
0
 protected function load($size = null)
 {
     try {
         $magick = new \Imagick();
         if ($this->format === IMG_JPG && $size !== null) {
             $magick->setOption('jpeg:size', $size[0] . 'x' . $size[1]);
             // some versions of Imagick only respond to this...
             $magick->setSize($size[0], $size[1]);
             // ...and others to this
         }
         $magick->readImage($this->filename);
     } catch (\Exception $e) {
         throw new \Imagine\Exception\RuntimeException("Imagick: Unable to open image {$this->filename}. {$e->getMessage()}", $e->getCode(), $e);
     }
     if ($this->format === IMG_JPG && $size !== null) {
         $newWidth = $magick->getImageWidth();
         if ($newWidth !== $this->size[0]) {
             $this->size = $this->prescalesize = array($newWidth, $magick->getImageHeight());
         }
     }
     $cs = $magick->getImageColorspace();
     $this->image = new Image($magick, RImagine::createPalette($cs), $this->metadata);
     if ($cs === \Imagick::COLORSPACE_CMYK) {
         // convert CMYK > RGB
         try {
             $this->image->usePalette(new RGB());
         } catch (\Exception $e) {
             $this->image->getImagick()->stripimage();
             // make sure all profiles are removed
         }
     }
 }
function powerpress_admin_init()
{
    global $wp_rewrite;
    add_thickbox();
    // we use the thckbox for some settings
    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-ui-core');
    // Now including the library at Google
    wp_enqueue_script('jquery-ui-tabs');
    // Powerpress page
    if (isset($_GET['page']) && strstr($_GET['page'], 'powerpress') !== false) {
        //wp_enqueue_script('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js');
        if (preg_match('/powerpressadmin_(mobile|audio|video)player/', $_GET['page'])) {
            wp_enqueue_style('wp-color-picker');
        }
        if (preg_match('/powerpressadmin_migrate/', $_GET['page'])) {
            wp_enqueue_script('media-upload');
            // For the readjustment of the thickbox only
        }
    }
    if (function_exists('powerpress_admin_jquery_init')) {
        powerpress_admin_jquery_init();
    }
    if (!current_user_can(POWERPRESS_CAPABILITY_MANAGE_OPTIONS)) {
        powerpress_page_message_add_error(__('You do not have sufficient permission to manage options.', 'powerpress'));
        return;
    }
    // Check for other podcasting plugin
    if (defined('PODPRESS_VERSION') || isset($GLOBALS['podcasting_player_id']) || isset($GLOBALS['podcast_channel_active']) || defined('PODCASTING_VERSION')) {
        powerpress_page_message_add_error(__('Another podcasting plugin has been detected, PowerPress is currently disabled.', 'powerpress'));
    }
    global $wp_version;
    $VersionDiff = version_compare($wp_version, 3.6);
    if ($VersionDiff < 0) {
        powerpress_page_message_add_error(__('Blubrry PowerPress requires Wordpress version 3.6 or greater.', 'powerpress'));
    }
    // Check for incompatible plugins:
    if (isset($GLOBALS['objWPOSFLV']) && is_object($GLOBALS['objWPOSFLV'])) {
        powerpress_page_message_add_error(__('The WP OS FLV plugin is not compatible with Blubrry PowerPress.', 'powerpress'));
    }
    // Security step, we must be in a powerpress/* page...
    if (isset($_GET['page']) && strstr($_GET['page'], 'powerpress/') !== false) {
        // Save settings here
        if (isset($_POST['Feed']) || isset($_POST['General'])) {
            check_admin_referer('powerpress-edit');
            $upload_path = false;
            $upload_url = false;
            $UploadArray = wp_upload_dir();
            if (false === $UploadArray['error']) {
                $upload_path = $UploadArray['basedir'] . '/powerpress/';
                $upload_url = $UploadArray['baseurl'] . '/powerpress/';
            }
            // Save the posted value in the database
            $Feed = isset($_POST['Feed']) ? $_POST['Feed'] : false;
            $General = isset($_POST['General']) ? $_POST['General'] : false;
            $FeedSlug = isset($_POST['feed_slug']) ? esc_attr($_POST['feed_slug']) : false;
            $Category = isset($_POST['cat']) ? intval($_POST['cat']) : false;
            $term_taxonomy_id = isset($_POST['ttid']) ? intval($_POST['ttid']) : false;
            $podcast_post_type = isset($_POST['podcast_post_type']) ? esc_attr($_POST['podcast_post_type']) : false;
            // New iTunes image
            if (!empty($_POST['itunes_image_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['itunes_image_file']['name']));
                $temp = $_FILES['itunes_image_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    if (!empty($filenameParts['extension'])) {
                        do {
                            $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                            $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                        } while (file_exists($upload_path . $filename));
                    }
                }
                // Check the image...
                if (file_exists($temp)) {
                    $ImageData = @getimagesize($temp);
                    $rgb = true;
                    // We assume it is RGB
                    if (defined('POWERPRESS_IMAGICK') && POWERPRESS_IMAGICK) {
                        if ($ImageData[2] == IMAGETYPE_PNG && extension_loaded('imagick')) {
                            $image = new Imagick($temp);
                            if ($image->getImageColorspace() != imagick::COLORSPACE_RGB) {
                                $rgb = false;
                            }
                        }
                    }
                    if (empty($ImageData['channels'])) {
                        $ImageData['channels'] = 3;
                    }
                    // Assume it's ok if we cannot detect it.
                    if ($ImageData) {
                        if ($rgb && ($ImageData[2] == IMAGETYPE_JPEG || $ImageData[2] == IMAGETYPE_PNG) && $ImageData[0] == $ImageData[1] && $ImageData[0] >= 1400 && $ImageData[0] <= 3000 && $ImageData['channels'] == 3) {
                            if (!move_uploaded_file($temp, $upload_path . $filename)) {
                                powerpress_page_message_add_error(__('Error saving iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the iTunes image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                            } else {
                                $Feed['itunes_image'] = $upload_url . $filename;
                                if (!empty($_POST['itunes_image_checkbox_as_rss'])) {
                                    $Feed['rss2_image'] = $upload_url . $filename;
                                }
                                //if( $ImageData[0] < 1400 || $ImageData[1] < 1400 )
                                //{
                                //	powerpress_page_message_add_error( __('iTunes image warning', 'powerpress')  .':	'. htmlspecialchars($_FILES['itunes_image_file']['name']) . __(' is', 'powerpress') .' '. $ImageData[0] .' x '.$ImageData[0]   .' - '. __('Image must be square 1400 x 1400 pixels or larger.', 'powerprss') );
                                //}
                            }
                        } else {
                            if ($ImageData['channels'] != 3 || $rgb == false) {
                                powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('Image must be in RGB color space (CMYK is not supported).', 'powerprss'));
                            } else {
                                if ($ImageData[0] != $ImageData[1]) {
                                    powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('Image must be square, 1400 x 1400 is the required minimum size.', 'powerprss'));
                                } else {
                                    if ($ImageData[0] != $ImageData[1] || $ImageData[0] < 1400) {
                                        powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('Image is too small, 1400 x 1400 is the required minimum size.', 'powerprss'));
                                    } else {
                                        if ($ImageData[0] != $ImageData[1] || $ImageData[0] > 3000) {
                                            powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('Image is too large, 3000 x 3000 is the maximum size allowed.', 'powerprss'));
                                        } else {
                                            powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']));
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        powerpress_page_message_add_error(__('Invalid iTunes image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']));
                    }
                }
            }
            // New RSS2 image
            if (!empty($_POST['rss2_image_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['rss2_image_file']['name']));
                $temp = $_FILES['rss2_image_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    if (!empty($filenameParts['basename']) && !empty($filenameParts['extension'])) {
                        do {
                            $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                            $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                        } while (file_exists($upload_path . $filename));
                    }
                }
                if (@getimagesize($temp)) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving RSS image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the RSS image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $Feed['rss2_image'] = $upload_url . $filename;
                    }
                } else {
                    powerpress_page_message_add_error(__('Invalid RSS image', 'powerpress') . ': ' . htmlspecialchars($_FILES['rss2_image_file']['name']));
                }
            }
            // New mp3 coverart image
            if (!empty($_POST['coverart_image_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['coverart_image_file']['name']));
                $temp = $_FILES['coverart_image_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    do {
                        $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                        $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                    } while (file_exists($upload_path . $filename));
                }
                if (@getimagesize($temp)) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving Coverart image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the coverart image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $_POST['TagValues']['tag_coverart'] = $upload_url . $filename;
                        $General['tag_coverart'] = $upload_url . $filename;
                    }
                } else {
                    powerpress_page_message_add_error(__('Invalid Coverat image', 'powerpress') . ': ' . htmlspecialchars($_FILES['coverart_image_file']['name']));
                }
            }
            // New poster image
            if (!empty($_POST['poster_image_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['poster_image_file']['name']));
                $temp = $_FILES['poster_image_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    do {
                        $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                        $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                    } while (file_exists($upload_path . $filename));
                }
                if (@getimagesize($temp)) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving Poster image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the poster image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $General['poster_image'] = $upload_url . $filename;
                    }
                } else {
                    powerpress_page_message_add_error(__('Invalid poster image', 'powerpress') . ': ' . htmlspecialchars($_FILES['poster_image_file']['name']));
                }
            }
            // New audio play icon image
            if (!empty($_POST['audio_custom_play_button_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['audio_custom_play_button_file']['name']));
                $temp = $_FILES['audio_custom_play_button_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    do {
                        $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                        $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                    } while (file_exists($upload_path . $filename));
                }
                if (@getimagesize($temp)) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving Play image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the play image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $General['audio_custom_play_button'] = $upload_url . $filename;
                    }
                } else {
                    powerpress_page_message_add_error(__('Invalid play icon image', 'powerpress') . ': ' . htmlspecialchars($_FILES['audio_custom_play_button_file']['name']));
                }
            }
            // New video play icon image
            if (!empty($_POST['video_custom_play_button_checkbox'])) {
                $filename = str_replace(" ", "_", basename($_FILES['video_custom_play_button_file']['name']));
                $temp = $_FILES['video_custom_play_button_file']['tmp_name'];
                if (file_exists($upload_path . $filename)) {
                    $filenameParts = pathinfo($filename);
                    do {
                        $filename_no_ext = substr($filenameParts['basename'], 0, (strlen($filenameParts['extension']) + 1) * -1);
                        $filename = sprintf('%s-%03d.%s', $filename_no_ext, rand(0, 999), $filenameParts['extension']);
                    } while (file_exists($upload_path . $filename));
                }
                $imageInfo = @getimagesize($temp);
                if ($imageInfo && $imageInfo[0] == $imageInfo[1] && $imageInfo[0] == 60) {
                    if (!move_uploaded_file($temp, $upload_path . $filename)) {
                        powerpress_page_message_add_error(__('Error saving Video Play icon image', 'powerpress') . ':	' . htmlspecialchars($_FILES['itunes_image_file']['name']) . ' - ' . __('An error occurred saving the Video Play icon image on the server.', 'powerprss') . ' ' . sprintf(__('Local folder: %s; File name: %s', 'powerpress'), $upload_path, $filename));
                    } else {
                        $General['video_custom_play_button'] = $upload_url . $filename;
                    }
                } else {
                    if ($imageInfo) {
                        powerpress_page_message_add_error(__('Invalid play icon image size', 'powerpress') . ': ' . htmlspecialchars($_FILES['video_custom_play_button_file']['name']));
                    } else {
                        powerpress_page_message_add_error(__('Invalid play icon image', 'powerpress') . ': ' . htmlspecialchars($_FILES['video_custom_play_button_file']['name']));
                    }
                }
            }
            if (isset($_POST['UpdateDisablePlayer'])) {
                $player_feed_slug = $_POST['UpdateDisablePlayer'];
                $General['disable_player'] = array();
                $GeneralPrev = get_option('powerpress_general');
                if (isset($GeneralPrev['disable_player'])) {
                    $General['disable_player'] = $GeneralPrev['disable_player'];
                }
                if (isset($_POST['DisablePlayerFor'])) {
                    $General['disable_player'][$player_feed_slug] = 1;
                } else {
                    unset($General['disable_player'][$player_feed_slug]);
                }
            }
            // Check to see if we need to update the feed title
            if ($FeedSlug && !$podcast_post_type) {
                $GeneralSettingsTemp = powerpress_get_settings('powerpress_general', false);
                if (!isset($GeneralSettingsTemp['custom_feeds'][$FeedSlug]) || $GeneralSettingsTemp['custom_feeds'][$FeedSlug] != $Feed['title']) {
                    if (!$General) {
                        $General = array();
                    }
                    if (!empty($GeneralSettingsTemp['custom_feeds'])) {
                        $General['custom_feeds'] = $GeneralSettingsTemp['custom_feeds'];
                    } else {
                        $General['custom_feeds'] = array();
                    }
                    $General['custom_feeds'][$FeedSlug] = $Feed['title'];
                }
            }
            // Update the settings in the database:
            if ($General) {
                if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-settings') {
                    if (!isset($General['display_player_excerpt'])) {
                        // If we are modifying appearance settings but this option was not checked...
                        $General['display_player_excerpt'] = 0;
                    }
                    // Set it to zero.
                    //if( !isset($General['display_player_disable_mobile']) )
                    //	$General['display_player_disable_mobile'] = 0;
                    $General['disable_dashboard_stats'] = 0;
                    if (!empty($_POST['DisableStatsInDashboard'])) {
                        $General['disable_dashboard_stats'] = 1;
                    }
                    if (!isset($General['disable_dashboard_news'])) {
                        $General['disable_dashboard_news'] = 0;
                    }
                    if (!isset($General['episode_box_mode'])) {
                        // Default not set, 1 = no duration/file size, 2 = yes duration/file size (default if not set)
                        $General['episode_box_mode'] = 1;
                    }
                    // 1 = no duration/file size (unchecked)
                    if (!isset($General['episode_box_embed'])) {
                        $General['episode_box_embed'] = 0;
                    }
                    if (!isset($General['embed_replace_player'])) {
                        $General['embed_replace_player'] = 0;
                    }
                    if (!isset($General['episode_box_no_player'])) {
                        $General['episode_box_no_player'] = 0;
                    }
                    if (!isset($General['episode_box_no_links'])) {
                        $General['episode_box_no_links'] = 0;
                    }
                    if (!isset($General['episode_box_no_player_and_links'])) {
                        $General['episode_box_no_player_and_links'] = 0;
                    }
                    if (!isset($General['episode_box_cover_image'])) {
                        $General['episode_box_cover_image'] = 0;
                    }
                    if (!isset($General['episode_box_player_size'])) {
                        $General['episode_box_player_size'] = 0;
                    }
                    if (!isset($General['episode_box_subtitle'])) {
                        $General['episode_box_subtitle'] = 0;
                    }
                    if (!isset($General['episode_box_summary'])) {
                        $General['episode_box_summary'] = 0;
                    }
                    if (!isset($General['episode_box_author'])) {
                        $General['episode_box_author'] = 0;
                    }
                    if (!isset($General['episode_box_explicit'])) {
                        $General['episode_box_explicit'] = 0;
                    }
                    if (!isset($General['episode_box_closed_captioned'])) {
                        $General['episode_box_closed_captioned'] = 0;
                    }
                    if (!isset($General['episode_box_itunes_image'])) {
                        $General['episode_box_itunes_image'] = 0;
                    }
                    if (!isset($General['episode_box_order'])) {
                        $General['episode_box_order'] = 0;
                    }
                    if (!isset($General['episode_box_feature_in_itunes'])) {
                        $General['episode_box_feature_in_itunes'] = 0;
                    } else {
                        $General['episode_box_order'] = 0;
                    }
                    if (!isset($General['allow_feed_comments'])) {
                        $General['allow_feed_comments'] = 0;
                    }
                    if (!isset($General['feed_links'])) {
                        $General['feed_links'] = 0;
                    }
                    // Advanced Features
                    if (!isset($General['player_options'])) {
                        $General['player_options'] = 0;
                    }
                    if (!isset($General['cat_casting'])) {
                        $General['cat_casting'] = 0;
                    }
                    if (!isset($General['channels'])) {
                        $General['channels'] = 0;
                    }
                    if (!isset($General['taxonomy_podcasting'])) {
                        $General['taxonomy_podcasting'] = 0;
                    }
                    if (!isset($General['posttype_podcasting'])) {
                        $General['posttype_podcasting'] = 0;
                    }
                    if (!isset($General['playlist_player'])) {
                        $General['playlist_player'] = 0;
                    }
                    if (!isset($General['metamarks'])) {
                        $General['metamarks'] = 0;
                    }
                    // Media Presentation Settings
                    $PlayerSettings = array();
                    if (!empty($_POST['PlayerSettings'])) {
                        $PlayerSettings = $_POST['PlayerSettings'];
                    }
                    if (empty($PlayerSettings['display_pinw'])) {
                        $PlayerSettings['display_pinw'] = 0;
                    }
                    if (empty($PlayerSettings['display_media_player'])) {
                        $PlayerSettings['display_media_player'] = 0;
                    }
                    if (empty($PlayerSettings['display_pinw'])) {
                        $PlayerSettings['display_pinw'] = 0;
                    }
                    if (empty($PlayerSettings['display_media_player'])) {
                        $PlayerSettings['display_media_player'] = 0;
                    }
                    $General['player_function'] = abs($PlayerSettings['display_pinw'] - $PlayerSettings['display_media_player']);
                    $General['podcast_link'] = 0;
                    if (!empty($PlayerSettings['display_download'])) {
                        $General['podcast_link'] = 1;
                        if (!empty($PlayerSettings['display_download_size'])) {
                            $General['podcast_link'] = 2;
                            if (!empty($PlayerSettings['display_download_duration'])) {
                                $General['podcast_link'] = 3;
                            }
                        }
                    }
                    if (!isset($General['podcast_embed'])) {
                        $General['podcast_embed'] = 0;
                    }
                    if (!isset($General['podcast_embed_in_feed'])) {
                        $General['podcast_embed_in_feed'] = 0;
                    }
                    if (!isset($General['m4a'])) {
                        $General['m4a'] = '';
                    }
                    if (!isset($General['new_window_nofactor'])) {
                        $General['new_window_nofactor'] = '';
                    }
                    if (!isset($General['subscribe_links'])) {
                        $General['subscribe_links'] = false;
                    }
                    if (!isset($General['subscribe_feature_email'])) {
                        $General['subscribe_feature_email'] = false;
                    }
                } else {
                    if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-defaults') {
                        if (!isset($General['display_player_excerpt'])) {
                            // If we are modifying appearance settings but this option was not checked...
                            $General['display_player_excerpt'] = 0;
                        }
                        // Set it to zero.
                        $General['disable_dashboard_stats'] = 0;
                        if (!empty($_POST['DisableStatsInDashboard'])) {
                            $General['disable_dashboard_stats'] = 1;
                        }
                        // Advanced Mode options
                        if (!isset($General['cat_casting'])) {
                            $General['cat_casting'] = 0;
                        }
                        if (!isset($General['channels'])) {
                            $General['channels'] = 0;
                        }
                        if (!isset($General['taxonomy_podcasting'])) {
                            $General['taxonomy_podcasting'] = 0;
                        }
                        if (!isset($General['posttype_podcasting'])) {
                            $General['posttype_podcasting'] = 0;
                        }
                        if (!isset($General['metamarks'])) {
                            $General['metamarks'] = 0;
                        }
                    }
                }
                if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-search') {
                    //$PowerPressSearch = $_POST['PowerPressSearch'];
                    $PowerPressSearchToggle = $_POST['PowerPressSearchToggle'];
                    if (empty($PowerPressSearchToggle['seo_feed_title'])) {
                        $General['seo_feed_title'] = 0;
                    }
                }
                if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-tags') {
                    if (!isset($General['write_tags'])) {
                        // If we are modifying appearance settings but this option was not checked...
                        $General['write_tags'] = 0;
                    }
                    // Set it to zero.
                    $TagValues = $_POST['TagValues'];
                    $GeneralPosted = $_POST['General'];
                    if (!empty($_POST['PowerPressTrackNumber'])) {
                        update_option('powerpress_track_number', $_POST['PowerPressTrackNumber']);
                    }
                    // Set all the tag values...
                    while (list($key, $value) = each($GeneralPosted)) {
                        if (substr($key, 0, 4) == 'tag_') {
                            // Special case, we are uploading new coverart image
                            if (!empty($_POST['coverart_image_checkbox']) && $key == 'tag_coverart') {
                                continue;
                            }
                            // Specail case, the track is saved in a separate column in the database.
                            if ($key == 'tag_track') {
                                continue;
                            }
                            if (!empty($value)) {
                                $General[$key] = $TagValues[$key];
                            } else {
                                $General[$key] = '';
                            }
                        }
                    }
                    if (!empty($General['tag_coverart'])) {
                        $GeneralSettingsTemp = powerpress_get_settings('powerpress_general', false);
                        if (!empty($GeneralSettingsTemp['blubrry_hosting']) && $GeneralSettingsTemp['blubrry_hosting'] !== 'false') {
                            $json_data = false;
                            $api_url_array = powerpress_get_api_array();
                            while (list($index, $api_url) = each($api_url_array)) {
                                $req_url = sprintf('%s/media/%s/coverart.json?url=%s', rtrim($api_url, '/'), $GeneralSettingsTemp['blubrry_program_keyword'], urlencode($TagValues['tag_coverart']));
                                $req_url .= defined('POWERPRESS_BLUBRRY_API_QSA') ? '&' . POWERPRESS_BLUBRRY_API_QSA : '';
                                $json_data = powerpress_remote_fopen($req_url, $GeneralSettingsTemp['blubrry_auth']);
                                if ($json_data != false) {
                                    break;
                                }
                            }
                            // Lets try to cache the image onto Blubrry's Server...
                            $results = powerpress_json_decode($json_data);
                            if (is_array($results) && !isset($results['error'])) {
                                // Good!
                                powerpress_page_message_add_notice(__('Coverart image updated successfully.', 'powerpress'));
                            } else {
                                if (isset($results['error'])) {
                                    $error = __('Blubrry Hosting Error (updating coverart)', 'powerpress') . ': ' . $results['error'];
                                    powerpress_page_message_add_error($error);
                                } else {
                                    $error = __('An error occurred updating the coverart with your Blubrry Services Account.', 'powerpress');
                                    powerpress_page_message_add_error($error);
                                }
                            }
                        } else {
                            powerpress_page_message_add_error(__('Coverart Image was not uploaded to your Blubrry Services Account. It will NOT be added to your mp3s.', 'powerpress'));
                        }
                    }
                }
                if (!empty($_POST['action']) && $_POST['action'] == 'powerpress-save-videocommon') {
                    if (!isset($General['poster_play_image'])) {
                        $General['poster_play_image'] = 0;
                    }
                    if (!isset($General['poster_image_audio'])) {
                        $General['poster_image_audio'] = 0;
                    }
                }
                // Wordpress adds slashes to everything, but since we're storing everything serialized, lets remove them...
                $General = powerpress_stripslashes($General);
                powerpress_save_settings($General);
            }
            if ($Feed) {
                if (!isset($_POST['ProtectContent']) && isset($Feed['premium'])) {
                    $Feed['premium'] = false;
                }
                if (!isset($Feed['enhance_itunes_summary'])) {
                    $Feed['enhance_itunes_summary'] = false;
                }
                if (!isset($Feed['itunes_author_post'])) {
                    $Feed['itunes_author_post'] = false;
                }
                if (!isset($Feed['itunes_block'])) {
                    $Feed['itunes_block'] = false;
                }
                if (!isset($Feed['itunes_complete'])) {
                    $Feed['itunes_complete'] = false;
                }
                if (!isset($Feed['maximize_feed'])) {
                    $Feed['maximize_feed'] = false;
                }
                if (!isset($Feed['episode_itunes_image'])) {
                    $Feed['episode_itunes_image'] = false;
                }
                $Feed = powerpress_stripslashes($Feed);
                if ($Category) {
                    powerpress_save_settings($Feed, 'powerpress_cat_feed_' . $Category);
                } else {
                    if ($term_taxonomy_id) {
                        powerpress_save_settings($Feed, 'powerpress_taxonomy_' . $term_taxonomy_id);
                    } else {
                        if ($podcast_post_type) {
                            $PostTypeSettings = array();
                            $PostTypeSettings[$FeedSlug] = $Feed;
                            powerpress_save_settings($PostTypeSettings, 'powerpress_posttype_' . $podcast_post_type);
                            powerpress_rebuild_posttype_podcasting();
                        } else {
                            if ($FeedSlug == false && get_option('powerpress_feed_podcast')) {
                                // If the settings were moved to the podcast channels feature...
                                powerpress_save_settings($Feed, 'powerpress_feed_podcast');
                            }
                            // save a copy here if that is the case.
                            powerpress_save_settings($Feed, 'powerpress_feed' . ($FeedSlug ? '_' . $FeedSlug : ''));
                        }
                    }
                }
            }
            if (isset($_POST['EpisodeBoxBGColor'])) {
                $GeneralSettingsTemp = get_option('powerpress_general');
                $SaveEpisdoeBoxBGColor['episode_box_background_color'] = array();
                if (isset($GeneralSettingsTemp['episode_box_background_color'])) {
                    $SaveEpisdoeBoxBGColor['episode_box_background_color'] = $GeneralSettingsTemp['episode_box_background_color'];
                }
                //  copy previous settings
                list($feed_slug_temp, $background_color) = each($_POST['EpisodeBoxBGColor']);
                $SaveEpisdoeBoxBGColor['episode_box_background_color'][$feed_slug_temp] = $background_color;
                powerpress_save_settings($SaveEpisdoeBoxBGColor);
            }
            // Anytime settings are saved lets flush the rewrite rules
            $wp_rewrite->flush_rules();
            // Settings saved successfully
            if (!empty($_POST['action'])) {
                switch ($_POST['action']) {
                    case 'powerpress-save-settings':
                    case 'powerpress-save-defaults':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-channel':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress Channel settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-category':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress Category Podcasting  settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-ttid':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress Taxonomy Podcasting settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-post_type':
                        powerpress_page_message_add_notice(__('Blubrry PowerPress Post Type Podcasting settings saved.', 'powerpress'));
                        break;
                    case 'powerpress-save-tags':
                        $General = get_option('powerpress_general');
                        if (empty($General['blubrry_hosting']) || $General['blubrry_hosting'] === 'false') {
                            powerpress_page_message_add_notice(__('ATTENTION: You must configure your Blubrry Services in the Blubrry PowerPress &gt; Basic Settings page in order to utilize this feature.', 'powerpress'));
                        } else {
                            powerpress_page_message_add_notice(__('Blubrry PowerPress MP3 Tag settings saved.', 'powerpress'));
                        }
                        break;
                    default:
                        powerpress_page_message_add_notice(__('Blubrry PowerPress settings saved.', 'powerpress'));
                        break;
                }
            }
        }
        // Handle POST actions...
        if (isset($_POST['action'])) {
            switch ($_POST['action']) {
                case 'powerpress-addfeed':
                    check_admin_referer('powerpress-add-feed');
                    $Settings = get_option('powerpress_general');
                    $key = sanitize_title($_POST['feed_slug']);
                    $value = $_POST['feed_name'];
                    $value = powerpress_stripslashes($value);
                    /*
                    					if( isset($Settings['custom_feeds'][ $key ]) && empty($_POST['overwrite']) )
                    					{
                    						powerpress_page_message_add_error( sprintf(__('Feed slug "%s" already exists.'), $key) );
                    					} else */
                    if ($key == '') {
                        powerpress_page_message_add_error(sprintf(__('Feed slug "%s" is not valid.', 'powerpress'), esc_html($_POST['feed_slug'])));
                    } else {
                        if (in_array($key, $wp_rewrite->feeds) && !isset($Settings['custom_feeds'][$key])) {
                            powerpress_page_message_add_error(sprintf(__('Feed slug "%s" is not available.', 'powerpress'), esc_html($key)));
                        } else {
                            $Settings['custom_feeds'][$key] = $value;
                            powerpress_save_settings($Settings);
                            add_feed($key, 'powerpress_do_podcast_feed');
                            // Before we flush the rewrite rules we need to add the new custom feed...
                            $wp_rewrite->flush_rules();
                            powerpress_page_message_add_notice(sprintf(__('Podcast Feed "%s" added, please configure your new feed now.', 'powerpress'), esc_html($value)));
                            $_GET['action'] = 'powerpress-editfeed';
                            $_GET['feed_slug'] = $key;
                        }
                    }
                    break;
                case 'powerpress-addtaxonomyfeed':
                    if (!empty($_POST['cancel'])) {
                        unset($_POST['taxonomy']);
                    }
                    if (empty($_POST['add_podcasting'])) {
                        break;
                    }
                    // We do not handle this situation
                case 'powerpress-addcategoryfeed':
                    check_admin_referer('powerpress-add-taxonomy-feed');
                    $taxonomy_type = isset($_POST['taxonomy']) ? $_POST['taxonomy'] : $_GET['taxonomy'];
                    $term_ID = intval(isset($_POST['term']) ? $_POST['term'] : $_GET['term']);
                    $term_object = get_term($term_ID, $taxonomy_type, OBJECT, 'edit');
                    if (empty($term_ID)) {
                        if ($taxonomy_type == 'category') {
                            powerpress_page_message_add_error(__('You must select a category to continue.', 'powerpress'));
                        } else {
                            powerpress_page_message_add_error(__('You must select a term to continue.', 'powerpress'));
                        }
                    } else {
                        if ($term_object == false) {
                            powerpress_page_message_add_error(__('Error obtaining term information.', 'powerpress'));
                        } else {
                            if ($taxonomy_type == 'category') {
                                $Settings = get_option('powerpress_general');
                                if (empty($Settings['custom_cat_feeds'])) {
                                    $Settings['custom_cat_feeds'] = array();
                                }
                                if (!in_array($term_ID, $Settings['custom_cat_feeds'])) {
                                    $Settings['custom_cat_feeds'][] = $term_ID;
                                    powerpress_save_settings($Settings);
                                }
                                powerpress_page_message_add_notice(__('Please configure your category podcast feed now.', 'powerpress'));
                                $_GET['action'] = 'powerpress-editcategoryfeed';
                                $_GET['cat'] = $term_ID;
                            } else {
                                //$term_info = term_exists($term_ID, $taxonomy_type);
                                $tt_id = $term_object->term_taxonomy_id;
                                if (!$tt_id) {
                                } else {
                                    $Settings = get_option('powerpress_taxonomy_podcasting');
                                    if (!isset($Settings[$tt_id])) {
                                        $Settings[$tt_id] = true;
                                        powerpress_save_settings($Settings, 'powerpress_taxonomy_podcasting');
                                        // add the feed to the taxonomy podcasting list
                                    }
                                    powerpress_page_message_add_notice(__('Please configure your taxonomy podcast now.', 'powerpress'));
                                    $_GET['action'] = 'powerpress-edittaxonomyfeed';
                                    $_GET['term'] = $term_ID;
                                    $_GET['ttid'] = $tt_id;
                                }
                            }
                        }
                    }
                    break;
                case 'powerpress-addposttypefeed':
                    check_admin_referer('powerpress-add-posttype-feed');
                    //die('ok 2');
                    $Settings = get_option('powerpress_general');
                    $feed_slug = sanitize_title($_POST['feed_slug']);
                    $post_type = $_POST['podcast_post_type'];
                    $post_type = powerpress_stripslashes($post_type);
                    $feed_title = $_POST['feed_title'];
                    $feed_title = powerpress_stripslashes($feed_title);
                    /*
                    					if( isset($Settings['custom_feeds'][ $key ]) && empty($_POST['overwrite']) )
                    					{
                    						powerpress_page_message_add_error( sprintf(__('Feed slug "%s" already exists.'), $key) );
                    					} else */
                    if (empty($feed_slug)) {
                        powerpress_page_message_add_error(sprintf(__('Feed slug "%s" is not valid.', 'powerpress'), esc_html($_POST['feed_slug'])));
                    } else {
                        if (empty($post_type)) {
                            powerpress_page_message_add_error(__('Post Type is invalid.', 'powerpress'));
                        } else {
                            $ExistingSettings = powerpress_get_settings('powerpress_posttype_' . $post_type);
                            if (!empty($ExistingSettings[$feed_slug])) {
                                powerpress_page_message_add_error(sprintf(__('Feed slug "%s" already exists.', 'powerpress'), $_POST['feed_slug']));
                            } else {
                                $NewSettings = array();
                                $NewSettings[$feed_slug]['title'] = $feed_title;
                                powerpress_save_settings($NewSettings, 'powerpress_posttype_' . $post_type);
                                add_feed($feed_slug, 'powerpress_do_podcast_feed');
                                // Before we flush the rewrite rules we need to add the new custom feed...
                                $wp_rewrite->flush_rules();
                                powerpress_page_message_add_notice(sprintf(__('Podcast "%s" added, please configure your new podcast.', 'powerpress'), $feed_title));
                                $_GET['action'] = 'powerpress-editposttypefeed';
                                $_GET['feed_slug'] = $feed_slug;
                                $_GET['podcast_post_type'] = $post_type;
                            }
                        }
                    }
                    break;
                case 'powerpress-ping-sites':
                    check_admin_referer('powerpress-ping-sites');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-ping-sites.php';
                    powerpressadmin_ping_sites_process();
                    $_GET['action'] = 'powerpress-ping-sites';
                    break;
                case 'powerpress-find-replace':
                    check_admin_referer('powerpress-find-replace');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-find-replace.php';
                    powerpressadmin_find_replace_process();
                    $_GET['action'] = 'powerpress-find-replace';
                    break;
                case 'powerpress-importpodpress':
                    check_admin_referer('powerpress-import-podpress');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-podpress.php';
                    powerpressadmin_podpress_do_import();
                    $_GET['action'] = 'powerpress-podpress-epiosdes';
                    break;
                case 'powerpress-importmt':
                    check_admin_referer('powerpress-import-mt');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-mt.php';
                    powerpressadmin_mt_do_import();
                    $_GET['action'] = 'powerpress-mt-epiosdes';
                    break;
                case 'deletepodpressdata':
                    check_admin_referer('powerpress-delete-podpress-data');
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-podpress.php';
                    powerpressadmin_podpress_delete_data();
                    break;
                case 'powerpress-save-mode':
                    //if( !isset($_POST['General']['advanced_mode']) )
                    //	powerpress_page_message_add_notice( __('You must select a Mode to continue.', 'powerpress') );
                    break;
            }
        }
        // Handle GET actions...
        if (isset($_GET['action'])) {
            switch ($_GET['action']) {
                case 'powerpress-enable-categorypodcasting':
                    check_admin_referer('powerpress-enable-categorypodcasting');
                    $Settings = get_option('powerpress_general');
                    $Settings['cat_casting'] = 1;
                    powerpress_save_settings($Settings);
                    wp_redirect('edit-tags.php?taxonomy=category&message=3');
                    exit;
                    break;
                case 'powerpress-addcategoryfeed':
                    check_admin_referer('powerpress-add-taxonomy-feed');
                    $cat_ID = intval($_GET['cat']);
                    $Settings = get_option('powerpress_general');
                    $category = get_category($cat_ID);
                    if ($category == false) {
                        powerpress_page_message_add_error(__('Error obtaining category information.', 'powerpress'));
                    } else {
                        if (empty($Settings['custom_cat_feeds']) || !is_array($Settings['custom_cat_feeds'])) {
                            $Settings['custom_cat_feeds'] = array();
                        }
                        if (!in_array($cat_ID, $Settings['custom_cat_feeds'])) {
                            $Settings['custom_cat_feeds'][] = $cat_ID;
                            powerpress_save_settings($Settings);
                        }
                        powerpress_page_message_add_notice(__('Please configure your category podcast feed now.', 'powerpress'));
                        $_GET['action'] = 'powerpress-editcategoryfeed';
                        $_GET['cat'] = $cat_ID;
                    }
                    break;
                case 'powerpress-delete-feed':
                    $delete_slug = $_GET['feed_slug'];
                    $force_deletion = !empty($_GET['force']);
                    check_admin_referer('powerpress-delete-feed-' . $delete_slug);
                    $Episodes = powerpress_admin_episodes_per_feed($delete_slug);
                    if (false && $delete_slug == 'podcast' && $force_deletion == false) {
                        powerpress_page_message_add_error(__('Cannot delete default podcast feed.', 'powerpress'));
                    } else {
                        if ($delete_slug != 'podcast' && $Episodes > 0 && $force_deletion == false) {
                            powerpress_page_message_add_error(sprintf(__('Cannot delete feed. Feed contains %d episode(s).', 'powerpress'), $Episodes));
                        } else {
                            $Settings = get_option('powerpress_general');
                            unset($Settings['custom_feeds'][$delete_slug]);
                            powerpress_save_settings($Settings);
                            // Delete the feed from the general settings
                            delete_option('powerpress_feed_' . $delete_slug);
                            // Delete the actual feed settings
                            // Now we need to update the rewrite cso the cached rules are up to date
                            if (in_array($delete_slug, $wp_rewrite->feeds)) {
                                $index = array_search($delete_slug, $wp_rewrite->feeds);
                                if ($index !== false) {
                                    unset($wp_rewrite->feeds[$index]);
                                }
                                // Remove the old feed
                            }
                            // Remove feed function hook
                            $hook = 'do_feed_' . $delete_slug;
                            remove_action($hook, $hook, 10, 1);
                            // This may not be necessary
                            $wp_rewrite->flush_rules();
                            // This is definitely necessary
                            powerpress_page_message_add_notice(__('Feed deleted successfully.', 'powerpress'));
                        }
                    }
                    break;
                case 'powerpress-delete-category-feed':
                    $cat_ID = intval($_GET['cat']);
                    check_admin_referer('powerpress-delete-category-feed-' . $cat_ID);
                    $Settings = get_option('powerpress_general');
                    $key = array_search($cat_ID, $Settings['custom_cat_feeds']);
                    if ($key !== false) {
                        unset($Settings['custom_cat_feeds'][$key]);
                        powerpress_save_settings($Settings);
                        // Delete the feed from the general settings
                    }
                    delete_option('powerpress_cat_feed_' . $cat_ID);
                    // Delete the actual feed settings
                    powerpress_page_message_add_notice(__('Removed podcast settings for category feed successfully.', 'powerpress'));
                    break;
                case 'powerpress-delete-taxonomy-feed':
                    $tt_ID = intval($_GET['ttid']);
                    check_admin_referer('powerpress-delete-taxonomy-feed-' . $tt_ID);
                    $Settings = get_option('powerpress_taxonomy_podcasting');
                    if (!empty($Settings[$tt_ID])) {
                        unset($Settings[$tt_ID]);
                        powerpress_save_settings($Settings, 'powerpress_taxonomy_podcasting');
                        // Delete the feed from the general settings
                    }
                    delete_option('powerpress_taxonomy_' . $tt_ID);
                    // Delete the actual feed settings
                    powerpress_page_message_add_notice(__('Removed podcast settings for term successfully.', 'powerpress'));
                    break;
                case 'powerpress-delete-posttype-feed':
                    // check admin referer prevents xss
                    $feed_slug = esc_attr($_GET['feed_slug']);
                    $post_type = esc_attr($_GET['podcast_post_type']);
                    check_admin_referer('powerpress-delete-posttype-feed-' . $post_type . '_' . $feed_slug);
                    $Settings = get_option('powerpress_posttype_' . $post_type);
                    if (!empty($Settings[$feed_slug])) {
                        unset($Settings[$feed_slug]);
                        update_option('powerpress_posttype_' . $post_type, $Settings);
                        //powerpress_save_settings($Settings, 'powerpress_posttype_'.$post_type); // Delete the feed from the general settings
                    }
                    powerpress_page_message_add_notice(__('Removed podcast settings for post type successfully.', 'powerpress'));
                    break;
                case 'powerpress-podpress-settings':
                    check_admin_referer('powerpress-podpress-settings');
                    // Import settings here..
                    if (powerpress_admin_import_podpress_settings()) {
                        powerpress_page_message_add_notice(__('Podpress settings imported successfully.', 'powerpress'));
                    } else {
                        powerpress_page_message_add_error(__('No Podpress settings found.', 'powerpress'));
                    }
                    break;
                case 'powerpress-podcasting-settings':
                    check_admin_referer('powerpress-podcasting-settings');
                    // Import settings here..
                    if (powerpress_admin_import_podcasting_settings()) {
                        powerpress_page_message_add_notice(__('Settings imported from the plugin "Podcasting" successfully.', 'powerpress'));
                    } else {
                        powerpress_page_message_add_error(__('No settings found for the plugin "Podcasting".', 'powerpress'));
                    }
                    break;
                case 'powerpress-add-caps':
                    check_admin_referer('powerpress-add-caps');
                    $users = array('administrator', 'editor', 'author');
                    // , 'contributor', 'subscriber');
                    while (list($null, $user) = each($users)) {
                        $role = get_role($user);
                        if (!empty($role)) {
                            if (!$role->has_cap('edit_podcast')) {
                                $role->add_cap('edit_podcast');
                            }
                            if ($user == 'administrator' && !$role->has_cap('view_podcast_stats')) {
                                $role->add_cap('view_podcast_stats');
                            }
                        }
                    }
                    $General = array('use_caps' => true);
                    powerpress_save_settings($General);
                    powerpress_page_message_add_notice(__('PowerPress Roles and Capabilities added to WordPress Blog.', 'powerpress'));
                    break;
                case 'powerpress-remove-caps':
                    check_admin_referer('powerpress-remove-caps');
                    $users = array('administrator', 'editor', 'author', 'contributor', 'subscriber');
                    while (list($null, $user) = each($users)) {
                        $role = get_role($user);
                        if (!empty($role)) {
                            if ($role->has_cap('edit_podcast')) {
                                $role->remove_cap('edit_podcast');
                            }
                            if ($role->has_cap('view_podcast_stats')) {
                                $role->remove_cap('view_podcast_stats');
                            }
                        }
                    }
                    $General = array('use_caps' => false);
                    powerpress_save_settings($General);
                    powerpress_page_message_add_notice(__('PowerPress Roles and Capabilities removed from WordPress Blog', 'powerpress'));
                    break;
                case 'powerpress-add-feed-caps':
                    check_admin_referer('powerpress-add-feed-caps');
                    $ps_role = get_role('premium_subscriber');
                    if (empty($ps_role)) {
                        add_role('premium_subscriber', __('Premium Subscriber', 'powerpress'));
                        $ps_role = get_role('premium_subscriber');
                        $ps_role->add_cap('read');
                        $ps_role->add_cap('premium_content');
                    }
                    $users = array('administrator', 'editor', 'author');
                    // , 'contributor', 'subscriber');
                    while (list($null, $user) = each($users)) {
                        $role = get_role($user);
                        if (!empty($role)) {
                            if (!$role->has_cap('premium_content')) {
                                $role->add_cap('premium_content');
                            }
                        }
                    }
                    $General = array('premium_caps' => true);
                    powerpress_save_settings($General);
                    powerpress_page_message_add_notice(__('Podcast Password Protection Capabilities for Custom Channel Feeds added successfully.', 'powerpress'));
                    break;
                case 'powerpress-remove-feed-caps':
                    check_admin_referer('powerpress-remove-feed-caps');
                    $users = array('administrator', 'editor', 'author', 'contributor', 'subscriber', 'premium_subscriber', 'powerpress');
                    while (list($null, $user) = each($users)) {
                        $role = get_role($user);
                        if (!empty($role)) {
                            if ($role->has_cap('premium_content')) {
                                $role->remove_cap('premium_content');
                            }
                        }
                    }
                    remove_role('premium_subscriber');
                    $General = array('premium_caps' => false);
                    powerpress_save_settings($General);
                    powerpress_page_message_add_notice(__('Podcast Password Protection Capabilities for Custom Channel Feeds removed successfully.', 'powerpress'));
                    break;
                case 'powerpress-clear-update_plugins':
                    check_admin_referer('powerpress-clear-update_plugins');
                    delete_option('update_plugins');
                    // OLD method
                    delete_option('_site_transient_update_plugins');
                    // New method
                    powerpress_page_message_add_notice(sprintf(__('Plugins Update Cache cleared successfully. You may now to go the %s page to see the latest plugin versions.', 'powerpress'), '<a href="' . admin_url() . 'plugins.php" title="' . __('Manage Plugins', 'powerpress') . '">' . __('Manage Plugins', 'powerpress') . '</a>'));
                    break;
            }
        }
        if (isset($_REQUEST['action'])) {
            switch ($_REQUEST['action']) {
                case 'powerpress-migrate-media':
                    require_once POWERPRESS_ABSPATH . '/powerpressadmin-migrate.php';
                    powerpress_admin_migrate_request();
                    break;
            }
        }
    }
    // Handle edit from category page
    if (isset($_POST['from_categories'])) {
        wp_redirect('edit-tags.php?taxonomy=category&message=3');
        exit;
    }
    // Hnadle player settings
    require_once POWERPRESS_ABSPATH . '/powerpressadmin-player.php';
    powerpress_admin_players_init();
}
Beispiel #17
0
 function _mkbilder($typ)
 {
     $handle = new Imagick();
     $img = new Imagick();
     if (!$handle->readImage("/tmp/tmp.file_org")) {
         return false;
     }
     $d = $handle->getImageGeometry();
     if ($d["width"] < $d["height"]) {
         $h = true;
         $faktor = 1 / ($d["height"] / $d["width"]);
     } else {
         $h = false;
         $faktor = $d["width"] / $d["height"];
     }
     $img->newImage($this->smallwidth, $this->smallheight, new ImagickPixel('white'));
     $img->setImageFormat($typ);
     $smallheight = floor($this->smallwidth * $faktor);
     $handle->thumbnailImage($this->smallwidth, $smallheight, true);
     $img->setImageColorspace($handle->getImageColorspace());
     $img->compositeImage($handle, imagick::GRAVITY_CENTER, 0, 0);
     $img->compositeImage($handle, $handle->getImageCompose(), 0, 0);
     $handle->clear();
     $handle->destroy();
     $rc = $img->writeImage("/tmp/tmp.file_small");
     $img->clear();
     $img->destroy();
     if (!$this->original) {
         $handle = new Imagick();
         $img->newImage($this->bigwidth, $this->bigheight, new ImagickPixel('white'));
         $img->setImageFormat($typ);
         $handle->readImage("/tmp/tmp.file_org");
         $bigheight = floor($this->bigwidth * $faktor);
         $handle->thumbnailImage($this->bigwidth, $bigheight, true);
         $img->compositeImage($handle, imagick::GRAVITY_CENTER, 0, 0);
         $handle->clear();
         $handle->destroy();
         return $img->writeImage("/tmp/tmp.file_org");
         $img->clear();
         $img->destroy();
     }
     return $rc;
 }
Beispiel #18
0
 private function createThumb($url, $filename, $type, $width, $height)
 {
     # Function that uses avconv to generate a thumbnail for a video file
     # Expects the following:
     # (string) $url : the path to the original video file
     # (string) $filename : the filename without path
     # (string) $type : dunno why this is needed right now, only mp4 is supported
     # (int) $width
     # (int) $height
     # Returns the following:
     # (bool) $return : true on success, false otherwise
     # Check dependencies
     self::dependencies(isset($this->database, $url, $filename, $this->settings, $type, $width, $height));
     # Call Plugins
     $this->plugins(__METHOD__, 0, func_get_args());
     #First step is to take a frame from the video which will then be resized
     $videoName = explode('.', $filename);
     $thumbOriginalName = $videoName[0] . "@original.jpg";
     $thumbOriginalPath = LYCHEE_UPLOADS_THUMB . $thumbOriginalName;
     $command = "avconv  -itsoffset -4  -i " . $url . " -vcodec mjpeg -vframes 1 -an -f rawvideo -s " . $width . "x" . $height . " " . $thumbOriginalPath;
     Log::notice($this->database, __METHOD__, __LINE__, "Command: " . $command);
     exec($command);
     # Next create the actual thumbnails using the same code as used for photos
     # Size of the thumbnail
     $newWidth = 200;
     $newHeight = 200;
     $iconWidth = 50;
     $iconHeight = 50;
     $videoName = explode('.', $filename);
     $newUrl = LYCHEE_UPLOADS_THUMB . $videoName[0] . '.jpeg';
     $newUrl2x = LYCHEE_UPLOADS_THUMB . $videoName[0] . '@2x.jpeg';
     # Create thumbnails with Imagick
     if (extension_loaded('imagick') && $this->settings['imagick'] === '1') {
         # Read icon image first
         $icon = new Imagick(LYCHEE . "/src/images/icon_play_overlay.png");
         # Read image
         $thumb = new Imagick();
         $thumb->readImage($thumbOriginalPath);
         $thumb->setImageCompressionQuality($this->settings['thumbQuality']);
         $thumb->setImageFormat('jpeg');
         #Set the colorspace of the icon to the same as the image
         $icon->setImageColorspace($thumb->getImageColorspace());
         # Copy image for 2nd thumb version
         $thumb2x = clone $thumb;
         $icon2x = clone $icon;
         # Create 1st version
         $thumb->cropThumbnailImage($newWidth, $newHeight);
         #Composite the icon
         $icon->cropThumbnailImage($iconWidth, $iconHeight);
         $thumb->compositeImage($icon, imagick::COMPOSITE_DEFAULT, $newWidth / 2 - $iconWidth / 2, $newHeight / 2 - $iconHeight / 2);
         #Save the small thumbnail
         $thumb->writeImage($newUrl);
         $thumb->clear();
         $thumb->destroy();
         # Create 2nd version
         $thumb2x->cropThumbnailImage($newWidth * 2, $newHeight * 2);
         # Composite the icon
         $icon2x->cropThumbnailImage($iconWidth * 2, $iconHeight * 2);
         $thumb2x->compositeImage($icon2x, imagick::COMPOSITE_DEFAULT, $newWidth - $iconWidth, $newHeight - $iconHeight);
         $thumb2x->writeImage($newUrl2x);
         $thumb2x->clear();
         $thumb2x->destroy();
     } else {
         # Read icon image first
         $iconPath = LYCHEE . "/src/images/icon_play_overlay.png";
         $iconSize = getimagesize($iconPath);
         $icon = imagecreatetruecolor($iconSize[0], $iconSize[1]);
         # Create image
         $thumb = imagecreatetruecolor($newWidth, $newHeight);
         $thumb2x = imagecreatetruecolor($newWidth * 2, $newHeight * 2);
         # Set position
         if ($width < $height) {
             $newSize = $width;
             $startWidth = 0;
             $startHeight = $height / 2 - $width / 2;
         } else {
             $newSize = $height;
             $startWidth = $width / 2 - $height / 2;
             $startHeight = 0;
         }
         # Create new image
         $sourceImg = imagecreatefromjpeg($thumbOriginalPath);
         $sourceIcon = imagecreatefrompng($iconPath);
         # Create thumb
         fastimagecopyresampled($thumb, $sourceImg, 0, 0, $startWidth, $startHeight, $newWidth, $newHeight, $newSize, $newSize);
         fastimagecopyresampled($thumb, $sourceIcon, $newWidth / 2 - $iconWidth / 2, $newHeight / 2 - $iconHeight / 2, 0, 0, $iconWidth, $iconHeight, $iconSize[0], $iconSize[1]);
         imagejpeg($thumb, $newUrl, $this->settings['thumbQuality']);
         imagedestroy($thumb);
         # Create retina thumb
         fastimagecopyresampled($thumb2x, $sourceImg, 0, 0, $startWidth, $startHeight, $newWidth * 2, $newHeight * 2, $newSize, $newSize);
         fastimagecopyresampled($thumb2x, $sourceIcon, $newWidth - $iconWidth, $newHeight - $iconHeight, 0, 0, $iconWidth * 2, $iconHeight * 2, $iconSize[0], $iconSize[1]);
         imagejpeg($thumb2x, $newUrl2x, $this->settings['thumbQuality']);
         imagedestroy($thumb2x);
         # Free memory
         imagedestroy($sourceImg);
         imagedestroy($sourceIcon);
     }
     # Finally delete the original thumbnail frame
     unlink($thumbOriginalPath);
     return true;
 }
Beispiel #19
0
 public function read($resource)
 {
     if (!is_resource($resource)) {
         throw new InvalidArgumentException('Variable does not contain a stream resource');
     }
     try {
         $magick = new \Imagick();
         $magick->readImageFile($resource);
     } catch (\ImagickException $e) {
         throw new RuntimeException("Imagick: Could not read image from resource. {$e->getMessage()}", $e->getCode(), $e);
     }
     $palette = self::createPalette($magick->getImageColorspace());
     return new RImage($magick, $palette, self::$emptyBag);
 }
     mkdir($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id']);
     mkdir($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name']);
     echo "创建文件目录成功!";
 }
 $im = new Imagick($path_pre . $v['diy_picture_path']);
 $im->thumbnailImage($size_arr['width'], $size_arr['height'], true);
 /* 改变大小 */
 $im->setInterlaceScheme(4);
 $lspath = basename($v['diy_picture_path']);
 $lspatharr = explode(".", $lspath);
 $am = $im->writeImage($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name'] . '/' . $lspatharr[0] . '-' . $v['updateid'] . '.' . $lspatharr[1]);
 if (!$am) {
     echo "图片压缩失败!";
 } else {
     $im_get = new \Imagick($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name'] . '/' . $lspatharr[0] . '-' . $v['updateid'] . '.' . $lspatharr[1]);
     $im_sta = $im_get->getImageColorspace();
     if (2 == $im_sta) {
         list($bg_width, $bg_height) = getimagesize($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name'] . '/' . $lspatharr[0] . '-' . $v['updateid'] . '.' . $lspatharr[1]);
         $bg_width -= 2;
         $bg_height -= 2;
         $imm = new \Imagick();
         $imm->newImage(2, 2, new \ImagickPixel('#FFFFFE'));
         $im_get->setImageColorSpace(1);
         $dww = new \ImagickDraw();
         $dww->setGravity(5);
         $dww->setFillOpacity(0.1);
         $dww->composite($imm->getImageCompose(), -$bg_width / 2, $bg_height / 2, 0, 0, $imm);
         $im_get->drawImage($dww);
         $im_get->writeImage($path_pre . '/Uploads/Uploads/' . $YMD . '/' . $v['cate_id'] . '/' . $v['attri_name'] . '/' . $lspatharr[0] . '-' . $v['updateid'] . '.' . $lspatharr[1]);
     }
     $im_get->clear();