use WideImage\WideImage; error_reporting(E_ALL & ~E_NOTICE); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $file = empty($_POST['imagePath']) ? "" : __DIR__ . '/..' . $_POST['imagePath']; $watermarkPath = empty($_POST['watermarkPath']) ? "" : __DIR__ . '/..' . $_POST['watermarkPath']; $scale = floatval($_POST['watermarkScale']); $opacity = (int) (floatval($_POST['opacity']) * 100); $coords = $_POST['position']; //die(var_dump($_POST)); // Если какого-то файла уже нет на сервере if (!file_exists($file) || !file_exists($watermarkPath)) { echo json_encode(array('error' => 2, 'message' => 'Одного или обоих файлов нет на сервере')); exit; } $image = WideImage::loadFromFile($file); $watermark = WideImage::loadFromFile($watermarkPath); list($width, $height) = getimagesize($watermarkPath); //$watermark = $watermark->resize(($width * $scale)); /* if ($width > $image->getWidth() && $image->getWidth()>$image->getHeight()) { $watermark = $watermark->resize($image->getWidth(), $height*$image->getWidth()/$width); } elseif ($height > $image->getHeight()) { $watermark = $watermark->resize($width*$image->getHeight()/$height, $image->getHeight()); } */ if ($width > $image->getWidth() || $height > $image->getHeight()) { $innerRatio = $width / $height; $outerRatio = $image->getWidth() / $image->getHeight(); if ($outerRatio < $innerRatio) { $watermark = $watermark->resize($image->getWidth(), $image->getWidth() / $innerRatio); } else {
/** * @expectedException WideImage\Exception\InvalidImageSourceException */ public function testInvalidImageFile() { WideImage::loadFromFile(IMG_PATH . 'fakeimage.png'); }