imagedestroy example

$original_resource = $this->getToolkit()->getResource();
    $original_type = $this->getToolkit()->getType();
    $data = [
      'width' => $width,
      'height' => $height,
      'extension' => $arguments['extension'],
      '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, $width$height$width$height)) {
        imagedestroy($original_resource);
        return TRUE;
      }
      // In case of error, reset resource and type to as it was.       $this->getToolkit()->setResource($original_resource);
      $this->getToolkit()->setType($original_type);
    }
    return FALSE;
  }

}
    // 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, $arguments['x']$arguments['y']$arguments['width']$arguments['height']$arguments['width']$arguments['height'])) {
        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;
  }

}
Shopware()->Db()->query($sql[$mailing]);
        }

        $this->Response()->headers->set('content-type', 'image/gif');
        $image = imagecreate(1, 1);
        if ($image === false) {
            return;
        }
        $white = (int) imagecolorallocate($image, 255, 255, 255);
        imagefill($image, 1, 1, $white);
        imagegif($image);
        imagedestroy($image);
    }

    /** * @deprecated in 5.6, will be private in 5.8 * * Init mailing method * * Initializes the mailing using the mailing id. * * @param int|null $mailingID * * @return array|null */
      // 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);
  }

  

function _rotate_image_resource( $img$angle ) {
    _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::rotate()' );

    if ( function_exists( 'imagerotate' ) ) {
        $rotated = imagerotate( $img$angle, 0 );

        if ( is_gd_image( $rotated ) ) {
            imagedestroy( $img );
            $img = $rotated;
        }
    }

    return $img;
}

/** * Flips an image resource. Internal use only. * * @since 2.9.0 * @deprecated 3.5.0 Use WP_Image_Editor::flip() * @see WP_Image_Editor::flip() * * @ignore * @param resource|GdImage $img Image resource or GdImage instance. * @param bool $horz Whether to flip horizontally. * @param bool $vert Whether to flip vertically. * @return resource|GdImage (maybe) flipped image resource or GdImage instance. */
$resource = @imagecreatefromstring(file_get_contents($value));

            if (false === $resource) {
                $this->context->buildViolation($constraint->corruptedMessage)
                    ->setCode(Image::CORRUPTED_IMAGE_ERROR)
                    ->addViolation();

                return;
            }

            imagedestroy($resource);
        }
    }
}
    // 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;
  }

}

        $rand = Random::getAlphanumericString(32);

        $string = md5($rand);
        $string = substr($string, 0, 5);

        $imgResource = $this->getImageResource($string);

        ob_start();
        imagepng($imgResource, null, 9);
        $img = (string) ob_get_clean();
        imagedestroy($imgResource);
        $img = base64_encode($img);

        return [
            'img' => $img,
            'sRand' => $rand,
        ];
    }

    /** * {@inheritdoc} */
    
imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255));
        break;

    }

    // Update the toolkit properties.     $this->getToolkit()->setType($type);
    $this->getToolkit()->setResource($res);

    // Destroy the original resource if it is not needed by other operations.     if (!$arguments['is_temp'] && is_resource($original_res)) {
      imagedestroy($original_res);
    }

    return TRUE;
  }

}
// Set the background color         // This won't work with transparent PNG files so we are         // going to have to figure out how to determine the color         // of the alpha channel in a future release.
        $white = imagecolorallocate($srcImg, 255, 255, 255);

        // Rotate it!         $destImg = imagerotate($srcImg$angle$white);

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

        $this->resource = $destImg;

        return true;
    }

    /** * Flattens transparencies * * @return $this */
    
class WP_Image_Editor_GD extends WP_Image_Editor {
    /** * GD Resource. * * @var resource|GdImage */
    protected $image;

    public function __destruct() {
        if ( $this->image ) {
            // We don't need the original in memory anymore.             imagedestroy( $this->image );
        }
    }

    /** * Checks to see if current environment supports GD. * * @since 3.5.0 * * @param array $args * @return bool */
    
// PHP installations using non-bundled GD do not have imagerotate.     if (!function_exists('imagerotate')) {
      $this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', ['%file' => $this->getToolkit()->getSource()]);
      return FALSE;
    }

    // Stores the original GD resource.     $original_res = $this->getToolkit()->getResource();

    if ($new_res = imagerotate($this->getToolkit()->getResource(), 360 - $arguments['degrees']$arguments['background_idx'])) {
      $this->getToolkit()->setResource($new_res);
      imagedestroy($original_res);

      // GIFs need to reassign the transparent color after performing the       // rotate, but only do so, if the image already had transparency of its       // own, or the rotate added a transparent background.       if (!empty($arguments['gif_transparent_color'])) {
        $transparent_idx = imagecolorexactalpha($this->getToolkit()->getResource()$arguments['gif_transparent_color']['red']$arguments['gif_transparent_color']['green']$arguments['gif_transparent_color']['blue']$arguments['gif_transparent_color']['alpha']);
        imagecolortransparent($this->getToolkit()->getResource()$transparent_idx);
      }

      return TRUE;
    }

    
$newImage = $this->createNewImage($image$originalSize$newSize$this->getImageExtension($destination));

        if ($this->fixGdImageBlur) {
            $this->fixGdImageBlur($newSize$newImage);
        }

        $this->saveImage($destination$newImage$quality);
        $this->optimizeImage($destination);

        // Removes both the original and the new created image from memory         imagedestroy($newImage);
        imagedestroy($image);
    }

    /** * Returns an array with a width and height index * according to the passed sizes * * @param resource $imageResource * * @return array{width: int, height: int} */
    
if ($originalImageSize === $thumbnailSize
                    && $mediaFilesystem->fileSize($originalUrl) < $mediaFilesystem->fileSize($url)) {
                    $mediaFilesystem->write($url$mediaFilesystem->read($originalUrl));
                }

                $savedThumbnails[] = [
                    'mediaId' => $media->getId(),
                    'width' => $size->getWidth(),
                    'height' => $size->getHeight(),
                ];

                imagedestroy($thumbnail);
            }
            imagedestroy($mediaImage);
        } finally {
            return $savedThumbnails;
        }
    }

    private function ensureConfigIsLoaded(MediaEntity $media, Context $context): void
    {
        $mediaFolderId = $media->getMediaFolderId();
        if ($mediaFolderId === null) {
            
$resource = @imagecreatefromstring(file_get_contents($value));

            if (false === $resource) {
                $this->context->buildViolation($constraint->corruptedMessage)
                    ->setCode(Image::CORRUPTED_IMAGE_ERROR)
                    ->addViolation();

                return;
            }

            imagedestroy($resource);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.