Processwire - Advanced Image Manipulation

Aus Wikizone
Version vom 1. August 2017, 11:04 Uhr von 37.49.32.84 (Diskussion)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

https://processwire.com/talk/topic/10483-image-quality/

https://processwire.com/talk/topic/261-where-to-set-image-resizing-quality-and-how-to-re-resize-images/

Konfiguration der Bildoptimierung[Bearbeiten]

ImageMagick statt GDLib nutzen[Bearbeiten]

Todo

Image Sizer Options[Bearbeiten]

In der config.php kann man Grundeinstellungen vornehmen.

Beispiel:

$config->imageSizerOptions = array(
	'upscaling' => false, // upscale if necessary to reach target size?
	'cropping' => true, // crop if necessary to reach target size?
	'autoRotation' => true, // automatically correct orientation?
	'sharpening' => 'soft', // sharpening: none | soft | medium | strong
	'quality' => 85, // quality: 1-100 where higher is better but bigger
);

Externe Bilder zu Feldern hinzufügen[Bearbeiten]

https://processwire.com/talk/topic/1501-using-an-external-image-and-resizing-it/

$page->video_image = 'http://domain.com/path/to/file.jpg';
$page->save();

Fügt beim Aufruf ein Bild aus einer externen Quelle hinzu und speichert es im Bildfeld

Once you've got the image in there, you can resize it like in your example. I'm assuming from the non-plural name 'video_image' that you've defined the field to only hold 1 image rather than many. Though the snippet above should work either way.

Note you may need to add a $page->of(false); before the code example above if you are executing it from a template file. ProcessWire delivers pages to templates in an output-ready state where entities are encoded and such (something you wouldn't want when saving a page). So you just have to disable output formatting to put the page in a state where it can be saved, otherwise ProcessWire will throw an error. This isn't usually necessary in other API contexts, outside of template files.

Image Processing vor dem Rendern der Seite auslösen[Bearbeiten]

https://processwire.com/talk/topic/13911-lazy-loading-of-images/ - Bilder beim Einpflegen resizen (nicht erst beim Page Rendern)

PW rendert die Bildvarianten beim Rendern der Bilder. Man kann aber über einen Hook auch Renderprozesse bereits beim Speichern der Seiten auslösen. Kann nützlich bei Seiten mit vielen Bildern der Seite sein.

see https://processwire.com/api/hooks/captain-hook/?filter=image
<?php
// hook to this method
protected function ___fileAdded(Pagefile $pagefile);

$this->addHookAfter('InputFieldImage::fileAdded', $this, 'createThumbnail');

// create the thumbnail
public function createThumbnail(HookEvent $event){
  $file = $event->return;
  // new thumb
  $page->image->width(200);	
}


https://processwire.com/talk/topic/13911-lazy-loading-of-images/