imagecolorstotal example

if ( ! $filename ) {
            $filename = $this->generate_filename( null, null, $extension );
        }

        if ( 'image/gif' === $mime_type ) {
            if ( ! $this->make_image( $filename, 'imagegif', array( $image$filename ) ) ) {
                return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } elseif ( 'image/png' === $mime_type ) {
            // Convert from full colors to index colors, like original PNG.             if ( function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) ) {
                imagetruecolortopalette( $image, false, imagecolorstotal( $image ) );
            }

            if ( ! $this->make_image( $filename, 'imagepng', array( $image$filename ) ) ) {
                return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } elseif ( 'image/jpeg' === $mime_type ) {
            if ( ! $this->make_image( $filename, 'imagejpeg', array( $image$filename$this->get_quality() ) ) ) {
                return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } elseif ( 'image/webp' == $mime_type ) {
            if ( ! function_exists( 'imagewebp' ) || ! $this->make_image( $filename, 'imagewebp', array( $image$filename$this->get_quality() ) ) ) {
                

  public function getTransparentColor() {
    if (!$this->getResource() || $this->getType() != IMAGETYPE_GIF) {
      return NULL;
    }
    // Find out if a transparent color is set, will return -1 if no     // transparent color has been defined in the image.     $transparent = imagecolortransparent($this->getResource());
    if ($transparent >= 0) {
      // Find out the number of colors in the image palette. It will be 0 for       // truecolor images.       $palette_size = imagecolorstotal($this->getResource());
      if ($palette_size == 0 || $transparent < $palette_size) {
        // Return the transparent color, either if it is a truecolor image         // or if the transparent color is part of the palette.         // Since the index of the transparent color is a property of the         // image rather than of the palette, it is possible that an image         // could be created with this index set outside the palette size.         // (see http://stackoverflow.com/a/3898007).         $rgb = imagecolorsforindex($this->getResource()$transparent);
        unset($rgb['alpha']);
        return Color::rgbToHex($rgb);
      }
    }
Home | Imprint | This part of the site doesn't use cookies.