I'm trying to create an image from a jpeg file (but it has some Adobe RGB, Gimp warning when opening a copy of it for conversion).
The original file is at http://learnintouch.com/Bernadotte.jpg
My source code:
The die statement will NOT display.
try {
$image = @imagecreatefromjpeg($file);
die("$file");
} catch (Exception $e) {
reportError("Could not use imagecreatefromjpeg() to create an image from the $file file.");
exit();
}
Or:
Only the print A displays.
try {
print("A");
$copy = imagecreatefrompng($filename);
print("B");
} catch (Exception $e) {
print("C");
reportError("Could not use imagecreatefrompng() to create an image from the $filename file. " . $e->getMessage());
exit();
}
The catch will NOT run.
The execution dies inside the imagecreatefromjpeg method.
I'm using PHP 5.6.16 and GD is:
GD Support enabled
GD Version bundled (2.1.0 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.4.9
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 8
PNG Support enabled
libPNG Version 1.2.49
WBMP Support enabled
XBM Support enabled
This is your problem:
@imagecreatefromjpeg($file);
The @
is an 'Error Control Operator' meant to suppress any errors . From the documentation:
Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.
My suspicion is that an exception is being raised, but because the @
has set the error level to 0, your reportError
function is not operating as you expect. (I can't confirm this without seeing that function, and perhaps knowing a bit more about your logging situation.) Regardless, you should remove the @
if you intend to handle errors in a try/catch
: the only time that operator is appropriate is if you need to suppress errors while bringing up the framework or code that would handle errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.