imagesx example

/** * Sets or updates current image size. * * @since 3.5.0 * * @param int $width * @param int $height * @return true */
    protected function update_size( $width = false, $height = false ) {
        if ( ! $width ) {
            $width = imagesx( $this->image );
        }

        if ( ! $height ) {
            $height = imagesy( $this->image );
        }

        return parent::update_size( $width$height );
    }

    /** * Resizes current image. * * Wraps `::_resize()` which returns a GD resource or GdImage instance. * * At minimum, either a height or width must be provided. If one of the two is set * to null, the resize will maintain aspect ratio according to the provided dimension. * * @since 3.5.0 * * @param int|null $max_w Image width. * @param int|null $max_h Image height. * @param bool|array $crop * @return true|WP_Error */

    public static function castStreamContext($stream, array $a, Stub $stub, bool $isNested)
    {
        return @stream_context_get_params($stream) ?: $a;
    }

    /** * @return array */
    public static function castGd($gd, array $a, Stub $stub, bool $isNested)
    {
        $a['size'] = imagesx($gd).'x'.imagesy($gd);
        $a['trueColor'] = imageistruecolor($gd);

        return $a;
    }

    /** * @return array */
    public static function castOpensslX509($h, array $a, Stub $stub, bool $isNested)
    {
        $stub->cut = -1;
        
$this->process($cmd);
    }

    /** * Return the width of an image. * * @return int */
    public function _getWidth()
    {
        return imagesx(imagecreatefromstring(file_get_contents($this->resource)));
    }

    /** * Return the height of an image. * * @return int */
    public function _getHeight()
    {
        return imagesy(imagecreatefromstring(file_get_contents($this->resource)));
    }

    

    public static function castStreamContext($stream, array $a, Stub $stub, bool $isNested)
    {
        return @stream_context_get_params($stream) ?: $a;
    }

    /** * @return array */
    public static function castGd($gd, array $a, Stub $stub, bool $isNested)
    {
        $a['size'] = imagesx($gd).'x'.imagesy($gd);
        $a['trueColor'] = imageistruecolor($gd);

        return $a;
    }

    /** * @return array */
    public static function castOpensslX509($h, array $a, Stub $stub, bool $isNested)
    {
        $stub->cut = -1;
        
// Perform our operation.     $image->apply($operation$arguments);

    // Flush Image object to disk storage.     $file_path = $this->directory . '/' . $test_case . image_type_to_extension($image->getToolkit()->getType());
    $image->save($file_path);

    // Check that the both the GD object and the Image object have an accurate     // record of the dimensions.     if (isset($expected['height']) && isset($expected['width'])) {
      $this->assertSame($expected['height']imagesy($toolkit->getResource()), "Image '$file_name' after '$test_case' should have a proper height.");
      $this->assertSame($expected['width']imagesx($toolkit->getResource()), "Image '$file_name' after '$test_case' should have a proper width.");
      $this->assertSame($expected['height']$image->getHeight(), "Image '$file_name' after '$test_case' should have a proper height.");
      $this->assertSame($expected['width']$image->getWidth(), "Image '$file_name' after '$test_case' should have a proper width.");
    }

    // Now check each of the corners to ensure color correctness.     foreach ($expected['corners'] as $key => $expected_color) {
      // The test gif that does not have transparency color set is a       // special case.       if ($file_name === 'image-test-no-transparency.gif') {
        if ($test_case == 'desaturate') {
          // For desaturating, keep the expected color from the test


    $this->setResource($resource);
    if (imageistruecolor($resource)) {
      return TRUE;
    }
    else {
      // Convert indexed images to truecolor, copying the image to a new       // truecolor resource, so that filters work correctly and don't result       // in unnecessary dither.       $data = [
        'width' => imagesx($resource),
        'height' => imagesy($resource),
        'extension' => image_type_to_extension($this->getType(), FALSE),
        'transparent_color' => $this->getTransparentColor(),
        'is_temp' => TRUE,
      ];
      if ($this->apply('create_new', $data)) {
        imagecopy($this->getResource()$resource, 0, 0, 0, 0, imagesx($resource)imagesy($resource));
        imagedestroy($resource);
      }
    }
    return (bool) $this->getResource();
  }
/** * Returns an array with a width and height index * according to the passed sizes * * @param resource $imageResource * * @return array{width: int, height: int} */
    private function getOriginalImageSize($imageResource): array
    {
        return [
            'width' => (int) imagesx($imageResource),
            'height' => (int) imagesy($imageResource),
        ];
    }

    /** * Determines the extension of the file according to * the given path and calls the right creation * method for the image extension * * @throws RuntimeException * * @return resource */
$this->resource = $src;
    }

    /** * Return image width. * * @return int */
    public function _getWidth()
    {
        return imagesx($this->resource);
    }

    /** * Return image height. * * @return int */
    public function _getHeight()
    {
        return imagesy($this->resource);
    }
}
    // the original resource on it with resampling. Destroy the original     // resource upon success.     $original_resource = $this->getToolkit()->getResource();
    $data = [
      'width' => $arguments['width'],
      'height' => $arguments['height'],
      'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
      'transparent_color' => $this->getToolkit()->getTransparentColor(),
      'is_temp' => TRUE,
    ];
    if ($this->getToolkit()->apply('create_new', $data)) {
      if (imagecopyresampled($this->getToolkit()->getResource()$original_resource, 0, 0, 0, 0, $arguments['width']$arguments['height']imagesx($original_resource)imagesy($original_resource))) {
        imagedestroy($original_resource);
        return TRUE;
      }
      else {
        // In case of failure, destroy the temporary resource and restore         // the original one.         imagedestroy($this->getToolkit()->getResource());
        $this->getToolkit()->setResource($original_resource);
      }
    }
    return FALSE;
  }

function _flip_image_resource( $img$horz$vert ) {
    _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::flip()' );

    $w   = imagesx( $img );
    $h   = imagesy( $img );
    $dst = wp_imagecreatetruecolor( $w$h );

    if ( is_gd_image( $dst ) ) {
        $sx = $vert ? ( $w - 1 ) : 0;
        $sy = $horz ? ( $h - 1 ) : 0;
        $sw = $vert ? -$w : $w;
        $sh = $horz ? -$h : $h;

        if ( imagecopyresampled( $dst$img, 0, 0, $sx$sy$w$h$sw$sh ) ) {
            imagedestroy( $img );
            


        return $image;
    }

    /** * @return array{width: int, height: int} */
    private function getOriginalImageSize(\GdImage $image): array
    {
        return [
            'width' => imagesx($image),
            'height' => imagesy($image),
        ];
    }

    /** * @param array{width: int, height: int} $imageSize * * @return array{width: int, height: int} */
    private function calculateThumbnailSize(
        array $imageSize,
        
Home | Imprint | This part of the site doesn't use cookies.