Make WordPress Core

Ticket #24871: 24871.diff

File 24871.diff, 2.4 KB (added by voldemortensen, 10 years ago)
  • tests/phpunit/tests/image/editor_imagick.php

     
    461461         */
    462462        public function test_image_preserves_alpha_on_resize() {
    463463                $file = DIR_TESTDATA . '/images/transparent.png';
    464 
    465464                $editor = wp_get_image_editor( $file );
    466465
    467466                $this->assertNotInstanceOf( 'WP_Error', $editor );
     
    472471
    473472                $editor->save( $save_to_file );
    474473
    475                 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     474                $im = new Imagick( $save_to_file );
     475                $pixel = $im->getImagePixelColor( 0, 0 );
     476                $expected = $pixel->getColorValue(imagick::COLOR_ALPHA);
    476477
     478                $this->assertImageAlphaAtPoint( $save_to_file, array( 0, 0 ), $expected );
     479
    477480                unlink( $save_to_file );
    478481        }
    479482
     
    484487         */
    485488        public function test_image_preserves_alpha() {
    486489                $file = DIR_TESTDATA . '/images/transparent.png';
    487 
    488490                $editor = wp_get_image_editor( $file );
    489 
    490491                $this->assertNotInstanceOf( 'WP_Error', $editor );
    491492
    492493                $editor->load();
    493 
    494494                $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
    495 
    496495                $editor->save( $save_to_file );
    497496
    498                 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     497                $im = new Imagick( $save_to_file );
     498                $pixel = $im->getImagePixelColor( 0, 0 );
     499                $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
    499500
     501                $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), $expected );
     502
    500503                unlink( $save_to_file );
    501504        }
    502505}
  • tests/phpunit/tests/image/base.php

     
    4242         * @param  array $point      array(x,y)
    4343         * @param  int $alpha
    4444         */
    45         protected function assertImageAlphaAtPoint( $image_path, $point, $alpha ) {
    46                 $im = imagecreatefrompng( $image_path );
    47                 $rgb = imagecolorat( $im, $point[0], $point[1] );
    48 
    49                 $colors = imagecolorsforindex( $im, $rgb );
    50 
    51                 $this->assertEquals( $alpha, $colors['alpha'] );
     45        protected function assertImageAlphaAtPoint( $image_path, $point, $expected ) {
     46                $im = new Imagick( $image_path );
     47                $pixel = $im->getImagePixelColor( $point[0], $point[1] );
     48                $color = $pixel->getColorValue(imagick::COLOR_ALPHA);           
     49                $this->assertEquals( $expected, $color );
    5250        }
    5351
    5452        /**