Download the PHP package by/first-image without Composer

On this page you can find all versions of the php package by/first-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package first-image

First Image plugin for Craft CMS 5.x

Get the first image from a Redactor or CKEditor field - optionally with an image transform applied.

Requirements

For Craft CMS 4, use by/first-image 2.x. For Craft CMS 3, use by/first-image 1.x.

Installation

  1. Open your terminal and go to your Craft project:

    cd /path/to/project
  2. Tell Composer to load the plugin:

    composer require uxi360/first-image
  3. Install the plugin, either from Settings → Plugins in the control panel or with:

    php craft plugin/install first-image

Upgrading to Craft 5 (from by/first-image)

As of 3.0.0 the package is named uxi360/first-image (it used to be by/first-image). The plugin handle is still first-image, so Craft treats it as the same plugin: there is nothing to uninstall or reinstall, and no template changes are required.

  1. Update Craft itself to Craft 5 first, following the Craft 5 upgrade guide.

  2. Swap the package in your project:

    composer remove by/first-image --no-update
    composer require uxi360/first-image:^3.0 -W

    Or edit your project's composer.json by hand, replacing

    "by/first-image": "2.0.0"

    with

    "uxi360/first-image": "^3.0.0"

    and run composer update by/first-image uxi360/first-image.

  3. Apply any pending changes and clear the compiled templates:

    php craft up
    php craft clear-caches/compiled-templates

Do not uninstall the plugin from the control panel while doing this - only the Composer package changes.

What changes for you:

Using First Image

getFirstImage is available as a Twig filter and as a Twig function. It returns the URL of the first image in the content, or null when there isn't one.

{{ entry.body | getFirstImage }}

or

{% set image = getFirstImage(entry.body) %}

Typical usage:

{% set image = entry.body | getFirstImage %}
{% if image %}
    <img src="{{ image }}" alt="{{ entry.title }}">
{% endif %}

Image transforms

Pass a transform the same way you would to asset.getUrl(). It works with both the filter and the function:

{{ entry.body | getFirstImage('thumb') }}
{{ getFirstImage(entry.body, 'thumb') }}

A named transform, by its handle:

{{ entry.body | getFirstImage('thumb') }}

A transform definition:

{{ entry.body | getFirstImage({
    mode: 'crop',
    width: 100,
    height: 100,
    quality: 75,
    position: 'top-center'
}) }}

Or from a variable, with the function syntax:

{% set thumb = { mode: 'fit', width: 600, format: 'webp' } %}
{% set image = getFirstImage(entry.body, thumb) %}

Transforms can only be applied to images that are Craft assets. In these cases the original image URL is returned unchanged:

Supported content

If an image has no src, its data-src attribute is used instead.

Brought to you by UXI360 InfoTech


All versions of first-image with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^4.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package by/first-image contains the following files

Loading the files please wait ...