/** * Provides markup for a product image gallery * * @api `shopp('product.gallery')` * @since 1.0 * * @param string $result The output * @param array $options The options * - **margins**: `20` Informs the PHP environment of the CSS margins used around elements for more accurate layout calculations * - **rowthumbs**: Sets the number of thumbnails per row to automatically resize the thumbnails to fit the space * - **p.setting**: Sets the image setting name to use for the preview image (individual settings can still be overridden) * - **p.size**: Sets the width and height of the preview image * - **p.width**: Sets the width of the preview image * - **p.height**: Sets the height of the preview image * - **p.fit**: `all` The fit of unproportional images to the requested size: * - **all**: Scale the image down to fit within the new size (the final size may differ from the specified dimensions) * - **crop**: Scale the image down to fit by the smallest dimension to fill the entire image, cropping the extra off the other dimension (specific cropping adjustments can be made in the product editor) * - **height**: Scale the image down to fit the image in the new size by the height, cropping any extra width * - **matte**: Scale the image down to fit within the new size filling extra space with a background color * - **width**: Scale the image down to fit the image in the new size by the width, cropping any extra height * - **p.sharpen**: `0` The amount of unsharp mask to use on the preview image * - **p.quality**: `80` (0%-100%) The JPEG image quality of the preview image * - **p.bg**: `#ffffff` (#rrggbb) The background color to use with the `matte` setting for the **p_fit** option * - **p.link**: `on` (on,off) Include a link to the original full-size image * - **rel**: Used to provide information about the relationship between the product and the linked image * - **thumbsetting**: Specifies the image setting name to use for thumbnail images (individual settings can still be overridden) * - **thumbsize**: Sets the width and height of the thumbnail images * - **thumbwidth**: Sets the width of the thumbnail images * - **thumbheight**: Sets the height of the thumbnail images * - **thumbfit**: `all` Sets fit of unproportional images to the requested size: * - **all**: Scale the image down to fit within the new size (the final size may differ from the specified dimensions) * - **crop**: Scale the image down to fit by the smallest dimension to fill the entire image, cropping the extra off the other dimension (specific cropping adjustments can be made in the product editor) * - **height**: Scale the image down to fit the image in the new size by the height, cropping any extra width * - **matte**: Scale the image down to fit within the new size filling extra space with a background color * - **width**: Scale the image down to fit the image in the new size by the width, cropping any extra height * - **thumbsharpen**: `0` The amount of unsharp mask to use on thumbnail images * - **thumbquality**: `80` (0%-100%) The JPEG image quality of the thumbnail images * - **thumbbg**: `#ffffff` (#rrggbb) The background color to use with the `matte` setting for the **thumbfit** option * - **zoomfx**: `shopp-zoom` Enables zoom (also known as a lightbox) effects for alternate JavaScript-based modal viewers. To change the built-in Colorbox options @use `shopp('storefront.zoom-options')` * - **preview**: `click` (click,hover,dblclick,mousedown) The browser action to use to preview a thumbnail * @param ShoppProduct $O The working object * @return string The gallery markup **/ public static function gallery($result, $options, $O) { if (empty($O->images)) { $O->load_data(array('images')); } if (empty($O->images)) { return false; } $_size = 240; $_width = shopp_setting('gallery_small_width'); $_height = shopp_setting('gallery_small_height'); if (!$_width) { $_width = $_size; } if (!$_height) { $_height = $_size; } $defaults = array('margins' => 20, 'rowthumbs' => false, 'p_setting' => false, 'p_size' => false, 'p_width' => false, 'p_height' => false, 'p_fit' => false, 'p_sharpen' => false, 'p_quality' => false, 'p_bg' => false, 'p_link' => true, 'rel' => '', 'thumbsetting' => false, 'thumbsize' => false, 'thumbwidth' => false, 'thumbheight' => false, 'thumbfit' => false, 'thumbsharpen' => false, 'thumbquality' => false, 'thumbbg' => false, 'zoomfx' => 'shopp-zoom', 'preview' => 'click'); // Populate defaults from named settings, if provided $ImageSettings = ImageSettings::object(); if (!empty($options['p_setting'])) { $settings = $ImageSettings->get($options['p_setting']); if ($settings) { $defaults = array_merge($defaults, $settings->options('p_')); } } if (!empty($options['thumbsetting'])) { $settings = $ImageSettings->get($options['thumbsetting']); if ($settings) { $defaults = array_merge($defaults, $settings->options('thumb')); } } $optionset = array_merge($defaults, $options); // Translate dot-notation options to underscore $options = array(); $keys = array_keys($optionset); foreach ($keys as $key) { $options[str_replace('.', '_', $key)] = $optionset[$key]; } extract($options); if ($p_size > 0) { $_width = $_height = $p_size; } $width = $p_width > 0 ? $p_width : $_width; $height = $p_height > 0 ? $p_height : $_height; $preview_width = $width; // Find the max dimensions to use for the preview spacing image $maxwidth = $maxheight = 0; foreach ($O->images as $img) { $scale = $p_fit ? array_search($p_fit, ImageAsset::$defaults['scaling']) : false; $scaled = $img->scaled($width, $height, $scale); $maxwidth = max($maxwidth, $scaled['width']); $maxheight = max($maxheight, $scaled['height']); } if (0 == $maxwidth) { $maxwidth = $width; } if (0 == $maxheight) { $maxheight = $height; } $p_link = Shopp::str_true($p_link); $product_class = 'product_' . (int) $O->id; // Setup preview images $previews = ''; if ('transparent' == strtolower($p_bg)) { $fill = -1; } else { $fill = $p_bg ? hexdec(ltrim($p_bg, '#')) : false; } $lowest_quality = min(ImageSetting::$qualities); $scale = $p_fit ? array_search($p_fit, ImageAsset::$defaults['scaling']) : false; $sharpen = $p_sharpen ? max($p_sharpen, ImageAsset::$defaults['sharpen']) : false; $quality = $p_quality ? max($p_quality, $lowest_quality) : false; foreach ($O->images as $Image) { $firstPreview = false; if (empty($previews)) { // Adds "filler" image to reserve the dimensions in the DOM $firstPreview = $previews .= '<li class="fill">' . '<img src="' . Shopp::clearpng() . '" alt="" style="width: ' . (int) $maxwidth . 'px; height: ' . (int) $maxheight . 'px;" />' . '</li>'; } $scaled = $Image->scaled($width, $height, $scale); $titleattr = !empty($Image->title) ? ' title="' . esc_attr($Image->title) . '"' : ''; $alt = esc_attr(!empty($Image->alt) ? $Image->alt : $Image->filename); $src = $Image->url($width, $height, $scale, $sharpen, $quality, $fill); $img = '<img src="' . $src . '"' . $titleattr . ' alt="' . $alt . '" width="' . (int) $scaled['width'] . '" height="' . (int) $scaled['height'] . '" />'; if ($p_link) { $hrefattr = $Image->url(); $relattr = empty($rel) ? '' : ' rel="' . esc_attr($rel) . '"'; $linkclasses = array('gallery', $product_class, $zoomfx); $img = '<a href="' . $hrefattr . '" class="' . join(' ', $linkclasses) . '"' . $relattr . $titleattr . '>' . $img . '</a>'; } $previews .= '<li id="preview-' . $Image->id . '"' . (empty($firstPreview) ? '' : ' class="active"') . '>' . $img . '</li>'; } $previews = '<ul class="previews">' . $previews . '</ul>'; $thumbs = ''; $twidth = $preview_width + $margins; // Add thumbnails (if needed) if (count($O->images) > 1) { $default_size = 64; $_thumbwidth = shopp_setting('gallery_thumbnail_width'); $_thumbheight = shopp_setting('gallery_thumbnail_height'); if (!$_thumbwidth) { $_thumbwidth = $default_size; } if (!$_thumbheight) { $_thumbheight = $default_size; } if ($thumbsize > 0) { $thumbwidth = $thumbheight = $thumbsize; } $width = $thumbwidth > 0 ? $thumbwidth : $_thumbwidth; $height = $thumbheight > 0 ? $thumbheight : $_thumbheight; $thumbs = ''; foreach ($O->images as $Image) { $scale = $thumbfit ? array_search($thumbfit, ImageAsset::$defaults['scaling']) : false; $sharpen = $thumbsharpen ? min($thumbsharpen, ImageAsset::$defaults['sharpen']) : false; $quality = $thumbquality ? min($thumbquality, ImageAsset::$defaults['quality']) : false; if ('transparent' == strtolower($thumbbg)) { $fill = -1; } else { $fill = $thumbbg ? hexdec(ltrim($thumbbg, '#')) : false; } $scaled = $Image->scaled($width, $height, $scale); $titleattr = empty($Image->title) ? '' : ' title="' . esc_attr($Image->title) . '"'; $alt = esc_attr(empty($Image->alt) ? $Image->name : $Image->alt); $src = $Image->url($width, $height, $scale, $sharpen, $quality, $fill); $thumbclasses = array('preview-' . $Image->id); if (empty($thumbs)) { $thumbclasses[] = 'first'; } $thumbclasses = esc_attr(join(' ', $thumbclasses)); $thumbs .= '<li id="thumbnail-' . $Image->id . '" class="' . $thumbclasses . '">' . '<img src="' . $src . '"' . $titleattr . ' alt="' . $alt . '" width="' . (int) $scaled['width'] . '" height="' . (int) $scaled['height'] . '" />' . '</li> '; } $thumbs = '<ul class="thumbnails">' . $thumbs . '</ul>'; } // end count($O->images) if ($rowthumbs > 0) { $twidth = ($width + $margins + 2) * (int) $rowthumbs; } $result = '<div id="gallery-' . $O->id . '" class="gallery">' . $previews . $thumbs . '</div>'; $script = "\t" . 'ShoppGallery("#gallery-' . $O->id . '","' . $preview . '"' . ($twidth ? ",{$twidth}" : "") . ');'; add_storefrontjs($script); return $result; }
/** * Generates image markup * * Internal Theme API helper but must remain publicly available for other Theme API classes to access. * * @internal * * @param string $result The output * @param array $options The options * - **alt**: The alt property of the image * - **bg**: The background color to use with the matte fit (#rrggbb) * - **class**: Specifies the CSS class of the image * - **fit**: The fit of unproportional images to the requested size: * - **all**: Scale the image down to fit within the new size (the final size may differ from the specified dimensions) * - **crop**: Scale the image down to fit by the smallest dimension to fill the entire image, cropping the extra off the other dimension (specific cropping adjustments can be made in the product editor) * - **height**: Scale the image down to fit the image in the new size by the height, cropping any extra width * - **matte**: Scale the image down to fit within the new size filling extra space with a background color * - **width**: Scale the image down to fit the image in the new size by the width, cropping any extra height * - **id**: Specify the image to show by the database ID * - **index**: Specify the index of the image to show * - **property**: (id,url,src,title,alt,width,height,class) Provide a property of the image rather than the image markup * - **quality**: The JPEG image quality (0-100%, default is 80) * - **sharpen**: Apply an unsharp mask to the image (100%-500%, default is none) * - **size**: The size to use for width and height of the image (used in place of width and height) * - **title**: The title property of the image * - **width**: The width of the image in pixels * - **height**: The height of the image in pixels * - **zoom**: `off` Enables the image zoom effect to view the original size image in a modal image viewer (Colorbox) * - **zoomfx**: `shopp-zoom` Enables zoom (also known as lightbox) effects for alternate JavaScript-based modal content viewers. * @param Object $O The working object * @return string The generated image markup **/ public static function image($result, $options, $O) { if (empty($O->images)) { return; } // Compatibility defaults $_size = 96; $_width = shopp_setting('gallery_thumbnail_width'); $_height = shopp_setting('gallery_thumbnail_height'); if (!$_width) { $_width = $_size; } if (!$_height) { $_height = $_size; } $defaults = array('alt' => '', 'bg' => false, 'class' => '', 'fit' => null, 'height' => false, 'id' => false, 'img' => false, 'index' => false, 'property' => false, 'quality' => null, 'setting' => '', 'sharpen' => null, 'size' => false, 'title' => '', 'width' => false, 'zoom' => false, 'zoomfx' => 'shopp-zoom'); // Populate defaults from named image settings to allow specific overrides if (!empty($options['setting'])) { $setting = $options['setting']; $ImageSettings = ImageSettings::object(); $settings = $ImageSettings->get($setting); if ($settings) { $defaults = array_merge($defaults, $settings->options()); } } $options = array_merge($defaults, $options); extract($options); // Select image by database id if (false !== $id) { if (isset($O->images[$id])) { $Image = $O->images[$id]; } else { shopp_debug(sprintf('No %s image exists with the specified database ID of %d.', get_class($O), $id)); return ''; } } // Select image by index position in the list if (false !== $index) { $keys = array_keys($O->images); if (isset($keys[$index]) && isset($O->images[$keys[$index]])) { $Image = $O->images[$keys[$index]]; } else { shopp_debug(sprintf('No %s image exists at the specified index position %d.', get_class($O), $id)); return ''; } } // Use the current image pointer by default if (!isset($Image)) { $Image = current($O->images); } if (false !== $size) { $width = $height = $size; } if (!$width) { $width = $_width; } if (!$height) { $height = $_height; } $lowest_quality = min(ImageSetting::$qualities); $scale = $fit ? array_search($fit, ImageAsset::$defaults['scaling']) : null; $sharpen = $sharpen ? max($sharpen, ImageAsset::$defaults['sharpen']) : null; $quality = $quality ? max($quality, $lowest_quality) : null; if ('transparent' == strtolower($bg)) { $fill = -1; } else { $fill = $bg ? hexdec(ltrim($bg, '#')) : false; } list($width_a, $height_a) = array_values($Image->scaled($width, $height, $scale)); if ('original' == $size) { $width_a = $Image->width; $height_a = $Image->height; } if ($width_a === false) { $width_a = $width; } if ($height_a === false) { $height_a = $height; } $alt = esc_attr(empty($alt) ? empty($Image->alt) ? $Image->name : $Image->alt : $alt); $title = empty($title) ? $Image->title : $title; $titleattr = empty($title) ? '' : ' title="' . esc_attr($title) . '"'; $classes = empty($class) ? '' : ' class="' . esc_attr($class) . '"'; $src = 'original' == $size ? $Image->url() : $Image->url($width, $height, $scale, $sharpen, $quality, $fill); switch (strtolower($property)) { case 'id': return $Image->id; break; case 'url': case 'src': return $src; break; case 'title': return $title; break; case 'alt': return $alt; break; case 'width': return $width_a; break; case 'height': return $height_a; break; case 'class': return $class; break; } $img = '<img src="' . $src . '"' . $titleattr . ' alt="' . $alt . '" width="' . (int) $width_a . '" height="' . (int) $height_a . '" ' . $classes . ' />'; if (Shopp::str_true($zoom)) { return '<a href="' . $Image->url() . '" class="' . $zoomfx . '" rel="product-' . $O->id . '"' . $titleattr . '>' . $img . '</a>'; } return $img; }
/** * Provides a reference to the instantiated singleton * * The ImageSettings class uses a singleton to ensure only one DB object is * instantiated at any time * * @author Jonathan Davis * @since 1.0 * * @return DB Returns a reference to the DB object **/ public static function &object() { if (!self::$object instanceof self) { self::$object = new self(); } return self::$object; }
// initialized only once, but calling Initialize() multiple times is also fine. PDFNet::Initialize(); //-------------------------------------------------------------------------------- // Example 1) Simple optimization of a pdf with default settings. // $doc = new PDFDoc($input_path . $input_filename . ".pdf"); $doc->InitSecurityHandler(); Optimizer::Optimize($doc); $doc->Save($output_path . $input_filename . "_opt1.pdf", SDFDoc::e_linearized); $doc->Close(); //-------------------------------------------------------------------------------- // Example 2) Reduce image quality and use jpeg compression for // non monochrome images. $doc = new PDFDoc($input_path . $input_filename . ".pdf"); $doc->InitSecurityHandler(); $image_settings = new ImageSettings(); // low quality jpeg compression $image_settings->SetCompressionMode(ImageSettings::e_jpeg); $image_settings->SetQuality(1); // Set the output dpi to be standard screen resolution $image_settings->SetImageDPI(144, 96); // this option will recompress images not compressed with // jpeg compression and use the result if the new image // is smaller. $image_settings->ForceRecompression(true); // this option is not commonly used since it can // potentially lead to larger files. It should be enabled // only if the output compression specified should be applied // to every image of a given type regardless of the output image size //$image_settings->ForceChanges(true); $opt_settings = new OptimizerSettings();