imagecopy example


function _crop_image_resource( $img$x$y$w$h ) {
    $dst = wp_imagecreatetruecolor( $w$h );

    if ( is_gd_image( $dst ) ) {
        if ( imagecopy( $dst$img, 0, 0, $x$y$w$h ) ) {
            imagedestroy( $img );
            $img = $dst;
        }
    }

    return $img;
}

/** * Performs group of changes on Editor specified. * * @since 2.9.0 * * @param WP_Image_Editor $image WP_Image_Editor instance. * @param array $changes Array of change operations. * @return WP_Image_Editor WP_Image_Editor instance with changes applied. */
// 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();
  }

  /** * {@inheritdoc} */
  public function isValid() {
    return ((bool) $this->preLoadInfo || (bool) $this->resource);
  }
$create = 'imagecreatetruecolor';
            $copy   = 'imagecopyresampled';
        } else {
            $create = 'imagecreate';
            $copy   = 'imagecopyresized';
        }
        $dest = $create($this->width, $this->height);

        $matte = imagecolorallocate($dest$red$green$blue);

        imagefilledrectangle($dest, 0, 0, $this->width, $this->height, $matte);
        imagecopy($dest$srcImg, 0, 0, 0, 0, $this->width, $this->height);

        // Kill the file handles         imagedestroy($srcImg);

        $this->resource = $dest;

        return $this;
    }

    /** * Flips an image along it's vertical or horizontal axis. * * @return $this */
Home | Imprint | This part of the site doesn't use cookies.