mewebstudio / captcha

Captcha for Laravel 5/6/7/8/9/10/11
MIT License
2.46k stars 453 forks source link

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

Closed light8771 closed 1 month ago

light8771 commented 2 months ago

domain/captcha/api Access error

image

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

ithsjeff commented 2 months ago

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

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

ariadys commented 2 months ago

same

ithsjeff commented 2 months ago

Okay, can you share more details so I can replicated and try fix it.

On Fri, Aug 23, 2024, 11:37 PM ariadys @.***> wrote:

same

— Reply to this email directly, view it on GitHub https://github.com/mewebstudio/captcha/issues/305#issuecomment-2307432661, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGJCHR4KAWYFPO2N2SHTIOTZS5QL7AVCNFSM6AAAAABMOINYB6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXGQZTENRWGE . You are receiving this because you commented.Message ID: @.***>

aleiku-syscom commented 2 months ago

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 commented 2 months ago

@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 commented 2 months ago

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

ithsjeff commented 1 month ago

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