Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined property: Intervention\Image\EncodedImage::$encoded #305

Open
light8771 opened this issue Aug 13, 2024 · 7 comments
Open

Undefined property: Intervention\Image\EncodedImage::$encoded #305

light8771 opened this issue Aug 13, 2024 · 7 comments

Comments

@light8771
Copy link

  • php 8.1.13
  • laravel 10.48.20
  • mews/captcha 3.4.1
  • intervention/image 3.7.2

domain/captcha/api Access error

image

I need to change the error line to 'img' => $this->image->encode()->toDataUri() to run normally

@ithsjeff
Copy link
Contributor

I had no problem after fixing the Providers problem here #306

If you still had a problem can you shared more detailed.

@ariadys
Copy link

ariadys commented Aug 23, 2024

same

@ithsjeff
Copy link
Contributor

ithsjeff commented Aug 23, 2024 via email

@aleiku-syscom
Copy link

PHP 8.3.10
Laravel 11.20.0
mews/captcha 3.4.2
intervention/image 3.8.0

Hi, due to the changes in version 3.8.0 of intervention/image,
the new ability to read instances of EncodedImage::class with ImageManager::class has been introduced.
However, the Intervention\Image\EncodedImage class no longer has the encode property.

<?php

declare(strict_types=1);

namespace Intervention\Image;

use Intervention\Image\Interfaces\EncodedImageInterface;

class EncodedImage extends File implements EncodedImageInterface
{
    /**
     * Create new instance
     *
     * @param string $data
     * @param string $mediaType
     */
    public function __construct(
        protected string $data,
        protected string $mediaType = 'application/octet-stream'
    ) {
    }

    /**
     * {@inheritdoc}
     *
     * @see EncodedImageInterface::mediaType()
     */
    public function mediaType(): string
    {
        return $this->mediaType;
    }

    /**
     * {@inheritdoc}
     *
     * @see EncodedImageInterface::mimetype()
     */
    public function mimetype(): string
    {
        return $this->mediaType();
    }

    /**
     * {@inheritdoc}
     *
     * @see EncodedImageInterface::toDataUri()
     */
    public function toDataUri(): string
    {
        return sprintf('data:%s;base64,%s', $this->mediaType, base64_encode($this->data));
    }
}

@light8771
Copy link
Author

@ithsjeff Hi, I updated to 3.4.2 and the problem is not solved

PHP 8.3.10 Laravel 11.20.0 mews/captcha 3.4.2 intervention/image 3.8.0

Hi, due to the changes in version 3.8.0 of intervention/image, the new ability to read instances of EncodedImage::class with ImageManager::class has been introduced. However, the Intervention\Image\EncodedImage class no longer has the encode property.

<?php

declare(strict_types=1);

namespace Intervention\Image;

use Intervention\Image\Interfaces\EncodedImageInterface;

class EncodedImage extends File implements EncodedImageInterface
{
    /**
     * Create new instance
     *
     * @param string $data
     * @param string $mediaType
     */
    public function __construct(
        protected string $data,
        protected string $mediaType = 'application/octet-stream'
    ) {
    }

    /**
     * {@inheritdoc}
     *
     * @see EncodedImageInterface::mediaType()
     */
    public function mediaType(): string
    {
        return $this->mediaType;
    }

    /**
     * {@inheritdoc}
     *
     * @see EncodedImageInterface::mimetype()
     */
    public function mimetype(): string
    {
        return $this->mediaType();
    }

    /**
     * {@inheritdoc}
     *
     * @see EncodedImageInterface::toDataUri()
     */
    public function toDataUri(): string
    {
        return sprintf('data:%s;base64,%s', $this->mediaType, base64_encode($this->data));
    }
}

@felixmertins
Copy link

we are facing same issue, after changing encoded to toDataURI() it works for us too.

@ithsjeff
Copy link
Contributor

ithsjeff commented Sep 4, 2024

@light8771 @felixmertins Okay, Waiting to this PR #309 to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants