Make WordPress Core


Ignore:
Timestamp:
05/25/2023 03:15:45 PM (13 months ago)
Author:
antpb
Message:

Media: Prevent scaling up of images in the Image Editor.

Previously, when scaling an image larger than the source size in the image edit states the image would silently fail the scaling action. This patch provides an error when someone attempts to scale an image larger than the source size while also disabling the button to initiate the action.

Props brookedot, joedolson, markoheijnen, mikeschroder, desrosj, Mista-Flo, costdev.
Fixes #26381.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/wpAjaxImageEditor.php

    r54722 r55859  
    6363
    6464    /**
     65     * @ticket 26381
     66     * @requires function imagejpeg
     67     *
     68     * @covers ::wp_save_image
     69     */
     70    public function testCropImageIntoLargerOne() {
     71        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
     72
     73        $filename = DIR_TESTDATA . '/images/canola.jpg';
     74        $contents = file_get_contents( $filename );
     75
     76        $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
     77        $id     = $this->_make_attachment( $upload );
     78
     79        $_REQUEST['action']  = 'image-editor';
     80        $_REQUEST['postid']  = $id;
     81        $_REQUEST['do']      = 'scale';
     82        $_REQUEST['fwidth']  = 700;
     83        $_REQUEST['fheight'] = 500;
     84
     85        $ret = wp_save_image( $id );
     86
     87        $this->assertObjectHasAttribute( 'error', $ret );
     88        $this->assertEquals( 'Images cannot be scaled to a size larger than the original.', $ret->error );
     89    }
     90
     91    /**
    6592     * @ticket 32171
    6693     * @requires function imagejpeg
Note: See TracChangeset for help on using the changeset viewer.