It’s not necessary foreach
to perform an operation so simple which can be written, if image is an array of 2 values (probably more, and probably used getimagesize
), if you have this:
array(7) {
[0]=> int(2048)
[1]=> int(852)
[2]=> int(2)
[3]=> string(25) "width="2048" height="852""
["bits"]=> int(8)
["channels"]=> int(3)
["mime"]=> string(10) "image/jpeg"
}
Just set directly:
$width = $image[0]; //0 é o indice da largura
$height = $image[1]; //1 é o indice da largura
$image = imagecreatetruecolor($width, $height);
An extra note, as I have already commented in another publication:
... «depreciated» is the wrong translation and this being misused and confused with the correct word, «depreciated» in English is «depreciated» and not «deprecated». The word «deprecated» that would be correct to refer to this would be translated as «obsolete», «disapproved», «censured». In the case of use here the best with certainty is «obsolete». Summarizing «depreciated» and «depreciated» has nothing to do with it
depreciated
– Guilherme Nascimento
Deprecated is a false cognate, like many words in English. For example, the word library gives impression that it is "bookstore", but means "library" (totally different). The term "depreciated" means something that has been diminished in value or price, which is quite different from "obsolete", which would be the most appropriate translation.
– Sam