internal package Foswiki::Plugins::ImagePlugin::Core

See PublishedAPI for packages intended to be used by Plugin and Contrib authors, or browse all packages.
See also Developing plugins, Developer's Bible, Technical Overview

On this page:

internal package Foswiki::Plugins::ImagePlugin::Core

Core class for the image service. A singleton instance is created by Foswiki::Plugins::ImagePlugin::getCore()

ClassMethod new($session) → $core

constructor

ObjectMethod cache() → $chiCache

returns a cache object. See Foswiki::Contrib::CacheContrib::getCache()

ObjectMethod json() → $json

returns a JSON object

ObjectMethod formatHtml5Data($key, $val) → $dataAttr

converts the given key-value pair into a proper HTML5 data attribute

ObjectMethod mage() → $imageMagick

returns a cached Image::Magick object. Note that this class maintains an image magick object using this methid used for the bulk of operations. Additional uncached Image::Magick object can be created using createImage().

ObjectMethod createImage() → $imageMagick

allocates a new Image::Magick object. Make sure you deallocate it on your own

ObjectMethod filter() → $filterService

returns a cached filter object. See Foswiki::Plugins::ImagePlugin::Filter.

ObjectMethod finishPlugin()

deallocates all delegates cached within this core object, i.e. cache, image magick, json and filter objects.

It also clears any outdated thumbnails left behind by image operations.

ObjectMethod handleREST($subject, $verb, $response) → $result

impements the process REST handler. available url parameters:

  • web
  • topic
  • file
  • refresh
  • size
  • zoom
  • width
  • height
  • filter
  • rotate
  • transparent
  • quality
  • output

ObjectMethod handleIMAGE($paramas, $topic, $web) → $result

impements the %IMAGE macro

ObjectMethod parseMediawikiParams($params)

This is a convenience method that tries to mimik image parameters as in MediaWiki. So instead of using individual parameters to the %IMAGE macro

  • type (link,frame,thumb)
  • file
  • width
  • height
  • size and
  • caption

caption are extracted from the %IMAGE default parameter.

ObjectMethod pingImage($imgInfo) → ($width, $height)

returns geometry info for the given info record. The $imgInfo parameter is a has reference that is enriched with the found width and height so that this method is safe to be called multiple times on the same image thus caching results within the $imgInfo record.

It processes the image in

  • imgPath

results are cached in

  • width
  • height

ObjectMethod pingOrigImage($imgInfo) → ($width, $height, $fileSize)

same as pingImage() but adding infos about the original image. results are cached in

It processes the image in

  • origImgPath

and stores results in

  • origWidth
  • origHeight

ObjectMethod ping($path) → ($width, $height)

reads image information for a file at $path. Note that other than the two above methods pingImage() and pingOrigImage() results are not cached whatsoever.

ObjectMethod processImage($web, $topic, $file, $params, $doRefresh) → $imgInfo

This is the central method that processes image within this core. It calculates the derived image or thumbnail based on the parameters given. The name of the resulting image file encodes information about the parameters being used to compute it encoded in md5. So this method will look out for an existing target and will only compute it if it doesn't exist yet or the boolean flag $doRefresh has been specified.

The $params hash may contain the following properties:

  • crop
  • filter
  • frame or layer
  • height
  • output
  • quality
  • rotate
  • size
  • transparent
  • type
  • width
  • zoom

Note that any filter parameter will be delegated to the Filter service at Foswiki::Plugins::ImagePlugin::Filter

ObjectMethod afterSaveHandler(undef, $topic, $web, $error, $meta)

extracts inline data images if configured so in the AutoAttachInlineImages setting of the plugin

ObjectMethod extractInlineImages($meta, $text) → $numImages

Extracts any inline data images within $text and returns the number of images found. These will be attached to an existing $meta object.

Note that $text is modified in place, replacing any found data with an appropriate markup to render the newly attached image. See the InlineImageTemplate plugin configuration.

ObjectMethod afterRenameHandler($oldWeb, $oldTopic, $oldAttachment, $newWeb, $newTopic, $newAttachment)

afterRename operations: flags old thumbnails as deleteable.

ObjectMethod flagThumbsForDeletion($web, $topic, $attachment)

This method reads all thumbnails on the given web.topic. These are the igp_md5... files which are then renamed by prepending the filename with an underscore (_).

If this thumbnail has to be recomputed yet again, it is re-renamed removing the underscore again. Any _igp_md5... files left are considered old and are deleted later on.

ObjectMethod clearAllThumbs($web, $topic, $attachment)

deletes all thumbnail files at the given web.topic, those named igp_md5...

ObjectMethod clearOutdatedThumbs($web, $topic, $attachment)

deletes all outdated thumbnail files at the given web.topic, those named _igp_md5.... Note the underscore infront of the name.

ObjectMethod clearMatchingThumbs($web, $topic, $attachment, $pattern)

delets all thumbnails for a given pattern

ObjectMethod takeOutSVG($text)

takes out all inline SVG files. Note that $text is modified in place.

ObjectMethod processInlineSvg($data) → $markup

processes any SVG file encoded in $data found by takeOutSVG(), attaches them to the current topic and returns appropriate markup to render it otherwise.

ObjectMethod inlineError($params)

creates an inline html alert message using the errorMsg property of this class. Warnings may be suppressed if $params->{warn} is switched off.

ObjectMethod mirrorImage($web, $topic, $url, $fileName, $force)

Downloads and mirrors an image and attach it to the given web.topic turns true on success. On false the errorMsg property is set.

ObjectMethod getImageFile($web, $topic, $topic, $params) → $fileName

returns an igp_md5... image name for the thumbnail to be processed based on the $params.

ObjectMethod updateAttachment($web, $topic, $fileName, $params)

saves the given file as an attachment to the web.topic

See Foswiki::Func::saveAttachment()

ObjectMethod getTemplate($name) → $tmpl

loads the named foswiki template or the default template "imageplugin". results are cached for performance reasons

ObjectMethod readMimeTypes() → $types

reads and caches the content of the MimeTypesFileName.

ObjectMethod mimeTypeToSuffix($mimeType) → $suffix

derives the appropriate file suffix for a given mime type

ObjectMethod suffixToMimeType($suffix) → $mimeType

returns the matching mime type for a given file extension

Topic revision: r1 - 21 Nov 2014, ProjectContributor
This site is powered by FoswikiCopyright © by the contributing authors. All material on this site is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback