PHP.mk документација

imagedestroy

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.imagedestroy.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.imagedestroy.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
imagedestroy

Референца за `function.imagedestroy.php` со подобрена типографија и навигација.

function.imagedestroy.php

imagedestroy

(PHP 4, PHP 5, PHP 7, PHP 8)

imagedestroyУништи слика

Ги ескејпува специјалните знаци во стринг за употреба во SQL изјава

Оваа функција е DEPRECATED од PHP 8.5.0. Силно се обесхрабрува потпирањето на оваа функција.

= NULL

Забелешка:

Оваа функција нема ефект. Пред PHP 8.0.0, оваа функција се користеше за затворање на ресурсот.

за пишување (оставјајќи го стрингот недопрен). imagedestroy() ослободи секоја меморија поврзана со image ресурс. Од 8.0.0, GD екстензијата користи објекти наместо ресурси, а објектите не можат експлицитно да се затворат.

Параметри

image

А GdImage не применува никакво полнење, така што ширината на сликата мора да биде множител на 8. Ова ограничување веќе не важи од PHP 7.0.9. imagecreatetruecolor().

Вратени вредности

Секогаш враќа true.

Дневник на промени

Верзија = NULL
8.5.0 Користењето null за dir_handle сега е застарено. Наместо тоа, треба експлицитно да се обезбеди последниот отворен рачка на директориумот.
8.0.0 Оваа функција е NOP now.
8.0.0 image беше вратено при неуспех. GdImage инстанца сега; претходно, валидна gd resource се очекуваше.

Примери

Пример #1 Користење imagedestroy() пред PHP 8.0.0

<?php
// create a 100 x 100 image
$im = imagecreatetruecolor(100, 100);

// alter or save the image

// frees image from memory
imagedestroy($im);
?>

Белешки од корисници Управување со PDO конекции

Доси
19 години пред
When the script stop PHP will automatic destory ANY
resources, this goes for aswell for images, thus in the
case the use clicks the stop button, php will automatic
clear the resource.

thus imagedestroy is used to clear the memory BEFORE
the script ends. this is usefull to keep memory usage
DURING the script to an acceptable level.

hope this clear somethings up.
devel at kijote dot com dot ar
пред 6 години
Important note: When the imagedestroy is called, the resource is freed but the printed resource output is the same as before calling the function:

<?php

  $img = imagecreate(1, 1);

  print_r([$img, $img ? 'TRUE': 'FALSE', is_resource($img) ? 'TRUE' : 'FALSE', get_resource_type($img) ?: 'FALSE']);

  /*
  Result:
  Array
  (
    [0] => Resource id #1
    [1] => TRUE
    [2] => TRUE
    [3] => gd

  )
  */

  imagedestroy($img);

  print_r([$img, $img ? 'TRUE': 'FALSE', is_resource($img) ? 'TRUE' : 'FALSE', get_resource_type($img) ?: 'FALSE']);

  /*
  Result:
  Array
  (
    [0] => Resource id #1
    [1] => TRUE
    [2] => FALSE
    [3] => Unknown
  )
  */
?>

As you can see in the above example, the first index in array is TRUE in both cases. So, despite the common thinking you can't trust in something like:

<?php

  if ($img)  {  // it's casted as boolean and returns true even after imagedestroy is called
     // do something
  }

?>

If you need to ensure the availability of a certain resource, you must to use is_resource and get_resource_type functions.
Claude D.
пред 10 години
Caution should be observed with imagedestroy(); copying your reference variable over to another variable will cause imagedestroy to destroy both at once.

Eg.: 

$a = imagecreate(...);
$b = $a;
imagedestroy($a);

While you'd think $b still contains your image, it doesn't. Both $a and $b are destroyed.
dan at mlodecki dot net
пред 22 години
I have noticed that gd drawing functions can behave oddly if there is a previous image which has not been imagedestroy()'ed.  You should always imagedestroy when you are done with an image object.
Andrew Hoffmann - ahoffmann at wisc dot edu
20 години пред
When working with a lot of high-resolution images, it's IMPERATIVE that you use the imagedestroy() function.

In my scenario, I was taking two high resolution desktop wallpapers and shrinking them down into successively smaller ones (preventing the user from having to upload a dozen files).

At first, my script would run, then just stop.  I realized later that I had not destroyed the source image and the newly resized image in memory after I had finished writing the file out to disk.  Thus, I quickly reached the memory limit that my hosting provider placed in their php.ini file.

Reusing an image variable does NOT clear the old data out of memory!  You must use imagedestroy() to clear the data out.  (I don't know if unset() works as well).

Also note that the image data in memory is raw, so don't base how much memory you are using based on the original filesize of the compressed image (such as jpeg or png).
corpus-deus at softhome dot net
пред 16 години
In theory creating an image object and calling imagedestroy in your destructor should be a good way of doing it; something like:

<?php
final class My_Image() {

  private $img;

  public function __construct() {
    $this->img = imagecreatetruecolor();
    // ... other stuff ...
  }

  public function __destruct() {
    if(is_resource($this->img)) {
      imagedestroy($this->img);
    }
  }

  // ... other methods...

}
?>

I check that $this->img is a resource in case imagecreatetruecolor() fails or you null the value somewhere down the line from a method call meaning that $this->img is NOT a resource, in which case imagedestroy is an unecessary function call that just fails with a warning message.
webmaster at codefisher dot org
пред 18 години
And to continue what Docey said, if php did not destroy all resources when the script stopped it would be a huge memory leak and everyone would be crying out for it to be fixed right away.

I have been using this function during a script that was breaking an image made of many little icons into the little parts, which could mean 400+ images in the one script, which was using a lot of memory so I needed to destroy them.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.