nng/nnfocalpoint

Focal Point Editor for TYPO3 images

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Type:typo3-cms-extension

pkg:composer/nng/nnfocalpoint

2.1.1 2025-12-12 09:17 UTC

This package is auto-updated.

Last update: 2025-12-12 09:18:10 UTC


README

TYPO3 12 TYPO3 13 License

A TYPO3 extension (v12 & v13) that adds an interactive focal point editor to sys_file_reference, allowing users to set focus points for different crop variants.

Features

  • Interactive Editor: Adds a "Fokus-Punkt bearbeiten" button below the crop options
  • Multi-Variant Support: Modal editor showing all crop variants as thumbnails
  • Click-to-Set: Click on the image to set a focal point for each crop variant
  • Visual Feedback: Focal points displayed on crop preview thumbnails
  • JSON Storage: Focal points stored as JSON with percentage coordinates (0-1)
  • ViewHelpers: Ready-to-use ViewHelpers for frontend integration

Documentation

Full documentation is available in the Documentation/ folder:

Installation

Composer (recommended)

composer require nng/nnfocalpoint

Classic Installation

  1. Copy the extension to typo3conf/ext/nnfocalpoint
  2. Activate the extension in the Extension Manager
  3. Run the Database Analyzer to add the tx_nnfocalpoint_points field
  4. Add the static template "Focal Point Editor" to your root page

Data Format

Focal points are stored in sys_file_reference.tx_nnfocalpoint_points as JSON:

{
  "default": {"x": 0.5, "y": 0.3},
  "landscape": {"x": 0.9, "y": 0.712},
  "portrait": {"x": 0.2, "y": 0.5}
}

Coordinates are percentages relative to the image:

  • x: 0 = left edge, x: 1 = right edge
  • y: 0 = top edge, y: 1 = bottom edge

Frontend Usage

The extension registers a global Fluid namespace nnfp. No namespace declaration needed!

Drop-in replacement for f:image:

<nnfp:image image="{image}" width="400" height="300" />

Automatically adds object-fit: cover; object-position: X% Y%; based on focal point.

Background images:

<div style="{nnfp:backgroundStyle(image: image, width: '1920')}">
    Hero content
</div>

Get CSS object-position value:

<img src="{image.publicUrl}" 
     style="object-fit: cover; object-position: {nnfp:objectPosition(image: image)}" />

Get focal point data:

<nnfp:focalPoint image="{image}" cropVariant="default" as="fp">
    <f:if condition="{fp}">
        Focal point: {fp.x} / {fp.y}
    </f:if>
</nnfp:focalPoint>

Focal crop - server-side cropping with focal point:

<!-- Crop to exact 400x200 dimensions, focal point stays centered -->
<nnfp:focalCrop image="{image}" width="400c" height="200" />

<!-- Get just the URI for use in custom markup -->
<img src="{nnfp:uri.focalCrop(image: image, width: '400c', height: '200')}" />

The "c" suffix indicates cropping. The image is cropped to the target aspect ratio with the focal point centered as much as possible, then scaled to the final dimensions.

Tip: nnfp:focalCrop can replace multiple crop variants! Instead of configuring desktop/tablet/mobile/square crop variants and having editors define each one, simply set a single focal point and use nnfp:focalCrop with any dimensions - the important part of the image stays visible automatically.

Available ViewHelpers

ViewHelperDescription
nnfp:imageDrop-in replacement for f:image with automatic focal point styling
nnfp:focalCropCrops image to exact dimensions with focal point centered
nnfp:uri.focalCropReturns URI of focal-point-cropped image
nnfp:backgroundStyleReturns complete style attribute for background images
nnfp:objectPositionReturns CSS object-position value (e.g., "50% 30%")
nnfp:focalPointReturns raw focal point data for custom logic

CSS Styles

Include the frontend CSS via TypoScript or by adding the static template "Focal Point Editor":

page.includeCSS.nnfocalpoint = EXT:nnfocalpoint/Resources/Public/Css/Frontend.css

Available CSS classes:

ClassDescription
.nnfp-imageAuto-added to nnfp:image output (width/height 100%, display block)
.nnfp-containerContainer with overflow hidden
.nnfp-container--16-916:9 aspect ratio container
.nnfp-container--4-34:3 aspect ratio container
.nnfp-container--1-1Square aspect ratio container
.nnfp-bgBackground image helper

Namespace

\Nng\Nnfocalpoint (global alias: nnfp)

Author

99grad - info@99grad.de