/** * @return stirng - Путь до изображения * @param string $file_name - Исходное изображение * @param CONST $scale_type - Способ масштабирования рисунка, одна из трех констант stRateably - Масштабирование с учетом пропорций, относительно $width или $height stSquare - Обрезать по квадрату со стороной $width stInSquare - Вписать в квадрат со стороной $width * @param int $width - Ширина конечного изображения, если == 0 не учитывается * @param int $height - Высота конечного изображения, если == 0 не учитывается * @param string $watermark - Способ наложения водяного знака. Одно из нескольких значений: 0 - Водяной знак не накладывается 1-9 - Водяной знак накладывается в одну из 9 позиций квадрата (см. документацию) * @desc МАКРОС: При необходимости масштабирует изображение под заданные параметры и возвращает путь до кешированного файла. */ public function resize($file_name, $scale_type, $width = 0, $height = 0, $watermark = 0) { if (!empty($file_name)) { if (system::checkVar($file_name, isAbsUrl)) { return $file_name; } $scale = !is_numeric($scale_type) ? constant($scale_type) : $scale_type; $dir = '/cache/img/' . $scale_type . '_' . $width . 'x' . $height . '_' . $watermark; $new_file = $dir . '/' . system::fileName($file_name); if (!file_exists(ROOT_DIR . $new_file)) { if (!is_dir(ROOT_DIR . $dir)) { @mkdir(ROOT_DIR . $dir, 0777); } $img = new resizer($file_name, $scale, $width, $height); if (is_numeric($watermark) && $watermark > 0) { $img->setWatermark(reg::getKey('/core/watermark'), $watermark); } $img->save(ROOT_DIR . $new_file); } if (file_exists(ROOT_DIR . $new_file)) { return $new_file; } } }
<?php if (!defined('PROPER_START')) { header("HTTP/1.0 403 Forbidden"); exit; } $userinfo = api::send('self/user/list'); $userinfo = $userinfo[0]; if ($_FILES['avatar']['error'] == UPLOAD_ERR_OK) { $resizer = new resizer($_FILES['avatar']['tmp_name'], 256, 256); $resizer->save('on/images/users/', $userinfo['id'] . '.png', resizer::PNG); } if (isset($_GET['redirect'])) { template::redirect($_GET['redirect']); } else { $template->redirect('/panel/settings'); }
if (empty($option[1])) { $para = ' -resize ' . $size . '\\! '; $this->command = ' convert ' . $para . ' ' . $this->source_image_url . ' :- 2>&1'; } switch (strtoupper($option[1])) { case 'S': $para = ' -resize ' . $size . '\\! '; $this->command = ' convert ' . $para . ' ' . $this->source_image_url . ' :- 2>&1'; break; case 'PC': $para = ' -resize ' . $size . '^ -gravity center -crop ' . $size . '+0+0 +repage '; $this->command = ' convert ' . $para . ' ' . $this->source_image_url . ' :- 2>&1'; break; default: $para = ' -resize ' . $size . '\\! '; $this->command = ' convert ' . $para . ' ' . $this->source_image_url . ' :- 2>&1'; break; } } /* Function is used to check file, prepare command to resize and resize */ public function resize() { $this->checkDestinationFile(); $this->prepare_command(); $this->do_resizing(); } } $objResizer = new resizer($_GET); $objResizer->resize();