Помогите вывести сообщение

VT
На сайте с 29.01.2015
Offline
0
413

Доброй ночи!

Админ сайта куда-то пропал.

Сам я программист, но PHP видел отрывками.

Помогите вывести название изменяемой картинки при ошибке.

Мои добавления в строчках, начинающихся на /*VitaliyTokarev*/

<?php

class ImageResizer {
function resize($src, $dest, $width, $height, $strict = false, $crop = false, $quality = 100) {
/*VitaliyTokarev*/ try{
if (file_exists($src)) {
$fileType = $this->getFileExtension($src);
$fileType = strtolower($fileType);
switch($fileType) {
case "jpeg":
case "jpg":
$srcImg = imagecreatefromjpeg($src);
break;
case "gif":
$srcImg = imagecreatefromgif($src);
break;
case "png":
$srcImg = imagecreatefrompng($src);
break;
}
$trueWidth = imagesx($srcImg);
$trueHeight = imagesy($srcImg);

if ($strict) {
if ($crop) {
$ratiox = $width / $trueWidth;
$ratioy = $height / $trueHeight;
$ratio = max($ratiox, $ratioy);
$newWidth = $trueWidth * $ratio;
$newHeight = $trueHeight * $ratio;
$cropx = ($newWidth - $width != 0) ? ($newWidth - $width) / 2 : 0;
$cropy = ($newHeight - $height != 0) ? ($newHeight - $height) / 2 : 0;
} else {
$newWidth = $width;
$newHeight = $height;
}
} else {
if ($trueWidth > $width || $trueHeight > $height) {
if (($trueWidth / $width) > ($trueHeight / $height)) {
$newWidth = $width;
$newHeight = ($trueHeight / ($trueWidth / $width));
} else {
$newWidth = ($trueWidth / ($trueHeight / $height));
$newHeight = $height;
}
} else {
$newWidth = $trueWidth;
$newHeight = $trueHeight;
}
}
if ($strict && $crop) {
$resampled = imagecreatetruecolor($newWidth, $newHeight);
if ($fileType == "png") imagealphablending($resampled, false);
$destImg = imagecreatetruecolor($width, $height);
imagecopyresampled($resampled, $srcImg, 0, 0, 0, 0, $newWidth, $newHeight, $trueWidth, $trueHeight);
imagecopy($destImg, $resampled, 0, 0, $cropx, $cropy, $newWidth, $newHeight);
} else {
$destImg = imagecreatetruecolor($newWidth, $newHeight);
if ($fileType == "png") imagealphablending($destImg, false);
imagecopyresampled($destImg, $srcImg, 0, 0, 0, 0, $newWidth, $newHeight, $trueWidth, $trueHeight);
}

// Save the resized image
switch ($fileType) {
case "jpeg":
case "jpg":
imagejpeg($destImg, $dest, $quality);
break;
case "gif":
imagegif($destImg, $dest);
break;
case "png":
imagesavealpha($destImg, true);
imagepng($destImg, $dest, 9);
break;
}
imagedestroy($destImg);
imagedestroy($srcImg);
if ($strict && $crop) {
imagedestroy($resampled);
}
/*VitaliyTokarev*/ }
/*VitaliyTokarev*/ catch
/*VitaliyTokarev*/ {
/*VitaliyTokarev*/ /*echo $src;*/ printf ({echo "test"});
/*VitaliyTokarev*/ echo "src = {$src}";
/*VitaliyTokarev*/ }
}
}

function addWatermark($src, $size = 'medium') {
if (file_exists($src)) {
$image = imagecreatefromjpeg($src);
$imagewidth = imagesx($image); $imageheight = imagesy($image);
$wm = imagecreatefrompng("files/watermark-$size.png");
$wmwidth = imagesx($wm); $wmheight = imagesy($wm);
$startwidth = 0; $startheight = $imageheight - $wmheight;
imagecopy($image, $wm, $startwidth, $startheight, 0, 0, $wmwidth, $wmheight);
imagejpeg($image, $src, 100);
imagedestroy($image); imagedestroy($wm);
}
}

function getFileExtension($str) {

$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
}
VT
На сайте с 29.01.2015
Offline
0
#1

Пробовал printf, echo... Не сработало. Что я делаю не так? Может здесь вообще напечатать нельзя? )))))

I
На сайте с 28.03.2011
Offline
37
#2

если вы в целях дебагинга это делаете, то можно заменить print и echo на die()

Помогаю не только словом.. (/ru/forum/830720)
Polkan
На сайте с 28.09.2005
Offline
102
#3

VitaliyTokarev, в целях дебаггинга лучше заменить print и echo на error_log() http://php.net/manual/ru/function.error-log.php

WordPress-плагин для Apishops (http://p-api-shop.ru/) P-API-Shop WooCommerce-плагин для Apishops (http://woo-apishops.ru/) Woo-Apishops

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий