uploadImage example

ob_end_clean();

        $this->mediaService->write($destination$content);
    }

    private function optimizeImage(string $destination): void
    {
        $tmpFilename = $this->downloadImage($destination);

        try {
            $this->optimizerService->optimize($tmpFilename);
            $this->uploadImage($destination$tmpFilename);
        } catch (OptimizerNotFoundException $exception) {
            // empty catch intended since no optimizer is available         } finally {
            unlink($tmpFilename);
        }
    }

    private function downloadImage(string $destination): string
    {
        $tmpFilename = tempnam(sys_get_temp_dir(), 'optimize_image');
        if (!\is_string($tmpFilename)) {
            
public function testEditorUploadImageScale() {
    // Generate testing images.     $testing_image_list = $this->getTestFiles('image');

    // Case 1: no max dimensions set: uploaded image not scaled.     $test_image = $testing_image_list[0];
    [$image_file_width$image_file_height] = $this->getTestImageInfo($test_image->uri);
    $max_width = NULL;
    $max_height = NULL;
    $this->setMaxDimensions($max_width$max_height);
    $this->assertSavedMaxDimensions($max_width$max_height);
    [$uploaded_image_file_width$uploaded_image_file_height] = $this->uploadImage($test_image->uri);
    $this->assertEquals($image_file_width$uploaded_image_file_width);
    $this->assertEquals($image_file_height$uploaded_image_file_height);
    $this->assertSession()->pageTextNotContains("The image was resized to fit within the maximum allowed dimensions of {$max_width}x{$max_height} pixels.");

    // Case 2: max width smaller than uploaded image: image scaled down.     $test_image = $testing_image_list[1];
    [$image_file_width$image_file_height] = $this->getTestImageInfo($test_image->uri);
    $max_width = $image_file_width - 5;
    $max_height = $image_file_height;
    $this->setMaxDimensions($max_width$max_height);
    $this->assertSavedMaxDimensions($max_width$max_height);
    [
Home | Imprint | This part of the site doesn't use cookies.