function index() { $id = isset($this->args[0]) ? (int) $this->args[0] : 0; $size = (isset($this->args[1]) and isset($this->ava_sizes[$this->args[1]])) ? $this->ava_sizes[$this->args[1]] : 0; $dir = $this->avatars_dir . '/' . $size; $file = $dir . '/' . $id; if (!is_dir($dir)) { mkdir($dir); } if (!is_file($file)) { $file = $dir . '/0'; if (!is_file($file)) { $src = $this->avatars_dir . '/avatar.jpg'; if ($size) { Images::resize($src, $file, $size); } else { copy($src, $file); } } } header('Content-type: image/jpg'); echo file_get_contents($file); }
public function copyFiles($settings, $gid) { //Допустимые типы $validTypes = array('image/jpg', 'image/jpeg', 'image/gif', 'image/wbmp'); //Поле с которого происходит выбор файлов Upload::$index = 'images'; //Максимальный размер в кб Upload::$size = 15000; //Передача типов в класс Upload::validType($validTypes); //Проверка валидности файлов $files = Upload::validate(); //Загрузка во временную директорию $result = Upload::uploadFiles($files, 'tmp', true); Bufer::add(array('result' => $result)); $dir_galery_pic = 'uploads/images/galery/' . $gid . '/pic'; $dir_galery_thumb = 'uploads/images/galery/' . $gid . '/thumb'; //Если есть файлы, прошедшие проверку if (!empty($result['valid'])) { foreach ($result['valid'] as $file) { $image = $file['hashname'] . '.' . $file['ext']; $preview_w = $settings['preview_w']; $preview_h = $settings['preview_h']; $quality = isset($settings['quality']) ? $settings['quality'] : 100; $imageInfo = getimagesize($file['fullpath'], $quality); $img = new Images($file['fullpath']); $resizeThumb = $img->resize($preview_w, $preview_h, $dir_galery_thumb, $image); $width = isset($settings['resize_w']) ? $settings['resize_w'] : $imageInfo[0]; $height = isset($settings['resize_h']) ? $settings['resize_h'] : $imageInfo[1]; $img = new Images($file['fullpath']); $resizeBig = $img->resize($width, $height, $dir_galery_pic, $image); if (isset($settings['watermark_text'])) { $alfa = $settings['water_set']['fontAlpha']; $position = $settings['water_set']['position']; $align = $settings['water_set']['align']; $font = $settings['water_set']['fontFamily']; $size = $settings['water_set']['fontSize']; $color = $settings['water_set']['fontColor']; $margin = $settings['water_set']['margin']; $text = $settings['watermark_text']; $img = new Images($dir_galery_pic . '/' . $image); $img->waterSettings(array('fontAlpha' => $alfa, 'fontSize' => $size, 'fontFamily' => $font, 'fontColor' => $color, 'position' => $position, 'align' => $align, 'margin' => 10)); $arrInfo = $img->waterMarkText($text, $dir_galery_pic, false); } if (isset($settings['watermark_image'])) { $alfa = $settings['water_set']['imgAlpha']; $position = $settings['water_set']['position']; $align = $settings['water_set']['align']; $margin = $settings['water_set']['margin']; $image = $settings['watermark_image']; $img = new Images($dir_galery_pic . '/' . $image); $img->waterSettings(array('imgAlpha' => $alfa, 'position' => $position, 'align' => $align, 'margin' => 10)); $arrInfo = $img->waterMarkImg($image, $dir_galery, false); } $images[] = array('pic' => $dir_galery_pic . '/' . $image, 'thumb' => $dir_galery_thumb . '/' . $image); Upload::deleteFile($file['fullpath']); } } if (isset($images) && isset($gid)) { $result = $this->addImagesOnDb($gid, $images); } }
G::AddJS('../plugins/js/jquery.cookie.js'); G::AddJS('bootstrap.min.js'); G::AddJS('../plugins/ckeditor/ckeditor.js'); G::AddJS('main.js'); G::AddJS('func.js'); $GLOBALS['__page_h1'] = ' '; if ($GLOBALS['CurrentController'] != 'productedit') { // G::AddCSS('adm.css'); } if (isset($_GET['check_art'])) { $Products = new Products(); echo "<!-- " . $Products->CheckArticle($_GET['check_art']) . "-->"; } if (isset($_GET['img'])) { $img = new Images(); $img->resize(false, false, strtotime($_GET['img'])); } if (isset($_GET['clear_thumbs'])) { $img = new Images(); $img->clearThumbs(); } // if($_SESSION['member']['id_user'] == 8569){ // // $sql = "SELECT * FROM "._DB_PREFIX_."image"; // // $result = $db->GetArray($sql); // // $xc = 0; // // foreach($result as $image){ // // print_r('<pre>'); // // if(!file_exists($GLOBALS['PATH_global_root'].$image['src'])){ // // $xc++; // // var_dump(file_exists($GLOBALS['PATH_global_root'].$image['src'])); // // $sql = "DELETE FROM "._DB_PREFIX_."image WHERE id = ".$image['id'];
public function AddPhotoProduct($data) { // try to create new product if (!($id_product = $this->AddProduct($data))) { return false; } $article = $this->GetArtByID($id_product); // try to add photos to the new product foreach ($data['images'] as $k => $image) { $to_resize[] = $newname = $article['art'] . ($k == 0 ? '' : '-' . $k) . '.jpg'; $file = pathinfo($image['src']); $path = $GLOBALS['PATH_root'] . $file['dirname'] . '/'; $bd_path = $file['dirname']; rename($path . $file['basename'], $path . $newname); $images_arr[] = $file['dirname'] . '/' . $newname; $visibility[] = $image['visible'] == 'true' ? 1 : 0; } //Проверяем ширину и высоту загруженных изображений, и если какой-либо из показателей выше 1000px, уменяьшаем размер foreach ($images_arr as $filename) { $size = getimagesize($GLOBALS['PATH_root'] . $filename); //Получаем ширину, высоту, тип картинки if ($size[0] > 1000 || $size[1] > 1000) { $ratio = $size[0] / $size[1]; //коэфициент соотношения сторон //Определяем размеры нового изображения if (max($size[0], $size[1]) == $size[0]) { $width = 1000; $height = 1000 / $ratio; } elseif (max($size[0], $size[1]) == $size[1]) { $width = 1000 * $ratio; $height = 1000; } } else { $width = $size[0]; $height = $size[1]; } $res = imagecreatetruecolor($width, $height); imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255)); $src = $size['mime'] == 'image/jpeg' ? imagecreatefromjpeg($GLOBALS['PATH_root'] . $filename) : imagecreatefrompng($GLOBALS['PATH_root'] . $filename); imagecopyresampled($res, $src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); imagejpeg($res, $GLOBALS['PATH_root'] . $filename); } $Images = new Images(); $Images->resize(false, $to_resize); $this->UpdatePhoto($id_product, $images_arr, $visibility); // try to add videos if (!empty($_POST['video'])) { $this->UpdateVideo($id_product, $_POST['video']); } // try to add new product to supplier's assort $Suppliers = new Suppliers(); $id_supplier = $Suppliers->GetSupplierIdByArt($data['art_supplier']); if (!$this->AddToAssort($id_product, $id_supplier)) { return false; } // Добавление данных в таблицу photo_batch $date = date('Y-m-d'); $id_author = $_SESSION['member']['id_user']; $id_batch = $this->GetIdPhotoBatch($date, $id_supplier, $id_author); if ($id_batch) { $this->AddPhotoBatchProducts($id_batch, $id_product); } else { $f['date'] = date('Y-m-d'); $f['id_supplier'] = $id_supplier; $f['id_author'] = $id_author; $this->db->StartTrans(); if (!$this->db->Insert(_DB_PREFIX_ . 'photo_batch', $f)) { $this->db->FailTrans(); return false; } $this->db->CompleteTrans(); $id_batch = $this->GetIdPhotoBatch($date, $id_supplier, $id_author); $this->AddPhotoBatchProducts($id_batch, $id_product); } return $id_product; }
public function parseUrl($url) { $Products = new Products(); $Specification = new Specification(); $Images = new Images(); $product = array(); $html = file_get_html($url); if (!$html) { return false; } // Название товара $product['name'] = $html->find('[itemprop="name"]', 0)->plaintext; if (!$product['name']) { return false; } // if($Products->SetFieldsByRewrite(G::StrToTrans($product['name']))){ // return false; // } // Описание товара $product['descr'] = $html->find('[itemprop="description"]', 0)->plaintext; // Указываем базовую активность товара $product['active'] = 1; // Получаем цену товара $product['price_opt_otpusk'] = $product['price_mopt_otpusk'] = $html->find('[itemprop="price"]', 0)->innertext; // Находим характеристики товара foreach ($html->find('.stats tr') as $element) { $caption = trim($element->find('.name span', 0)->innertext); if ($caption == 'Артикул') { $sup_comment = trim($element->children(1)->plaintext); } elseif ($caption !== '' && !in_array($caption, array('Доставка', 'Самовывоз', 'Гарантия'))) { $value = trim($element->children(1)->plaintext); $spec = $Specification->SpecExistsByCaption($caption); $product['specs'][] = array('id_spec' => $spec ? $spec['id'] : $Specification->Add(array('caption' => $caption)), 'value' => $value); } } // Выбираем изображения максимального размера foreach ($html->find('#photo #elementTableImg img') as $element) { $filename = 'http://zona220.com' . str_replace('/500_500_1/', '/', str_replace('/resize_cache/', '/', $element->src)); $img_info = array_merge(getimagesize($filename), pathinfo($filename)); $path = $GLOBALS['PATH_product_img'] . 'original/' . date('Y') . '/' . date('m') . '/' . date('d') . '/'; $Images->checkStructure($path); copy($filename, $path . $img_info['basename']); $product['images'][] = str_replace($GLOBALS['PATH_global_root'], '/', $path . $img_info['basename']); $product['images_visible'][] = 1; } $html->clear(); unset($html); // Добавляем новый товар в БД if ($id_product = $Products->AddProduct($product)) { // Добавляем характеристики новому товару if (!empty($product['specs'])) { foreach ($product['specs'] as $specification) { $Specification->AddSpecToProd($specification, $id_product); } } // Формирем массив записи ассортимента $assort = array('id_assortiment' => false, 'id_supplier' => 25392, 'id_product' => $id_product, 'price_opt_otpusk' => $product['price_opt_otpusk'], 'price_mopt_otpusk' => $product['price_mopt_otpusk'], 'active' => 0, 'inusd' => 0, 'sup_comment' => $sup_comment); // $assort = array('id_assortiment' => false, 'id_supplier' => 23029, 'id_product' => $id_product, 'price_opt_otpusk' => $product['price_opt_otpusk'], 'price_mopt_otpusk' => $product['price_mopt_otpusk'], 'active' => 0, 'inusd' => 0); // Добавляем зпись в ассортимент $Products->AddToAssortWithAdm($assort); // Получаем артикул нового товара $article = $Products->GetArtByID($id_product); // Переименовываем фото товара $to_resize = $images_arr = array(); if (isset($product['images'])) { foreach ($product['images'] as $k => $image) { $to_resize[] = $newname = $article['art'] . ($k == 0 ? '' : '-' . $k) . '.jpg'; $file = pathinfo(str_replace('/' . str_replace($GLOBALS['PATH_global_root'], '', $GLOBALS['PATH_product_img']), '', $image)); $path = $GLOBALS['PATH_product_img'] . trim($file['dirname']) . '/'; $images_arr[] = str_replace($file['basename'], $newname, $image); rename($path . $file['basename'], $path . $newname); } } //Проверяем ширину и высоту загруженных изображений, и если какой-либо из показателей выше 1000px, уменяьшаем размер foreach ($images_arr as $filename) { $file = $GLOBALS['PATH_product_img'] . str_replace('/' . str_replace($GLOBALS['PATH_global_root'], '', $GLOBALS['PATH_product_img']), '', $filename); $size = getimagesize($file); // $size = getimagesize($path.$filename); //Получаем ширину, высоту, тип картинки $width = $size[0]; $height = $size[1]; if ($size[0] > 1000 || $size[1] > 1000) { $ratio = $size[0] / $size[1]; //коэфициент соотношения сторон //Определяем размеры нового изображения if (max($size[0], $size[1]) == $size[0]) { $width = 1000; $height = 1000 / $ratio; } elseif (max($size[0], $size[1]) == $size[1]) { $width = 1000 * $ratio; $height = 1000; } } $res = imagecreatetruecolor($width, $height); imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255)); $src = $size['mime'] == 'image/jpeg' ? imagecreatefromjpeg($file) : imagecreatefrompng($file); imagecopyresampled($res, $src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); $stamp = imagecreatefrompng($GLOBALS['PATH_global_root'] . 'images/watermark.png'); imagecopyresampled($res, $stamp, 10, 10, 0, 0, imagesx($stamp), imagesy($stamp), imagesx($stamp), imagesy($stamp)); imagejpeg($res, $file); } $Images->resize(false, $to_resize); // Привязываем новые фото к товару в БД $Products->UpdatePhoto($id_product, $images_arr, $product['images_visible']); } return $id_product; }
break; } if ($bb >= $images_limit) { break; } } echo "<script>alert('Сгенерировано изображений: 120x90 - " . $aa . ", 250x250 - " . $ii . ", 500x500 - " . $bb . "');window.location.replace('" . $GLOBALS['URL_base'] . "adm');</script>"; } // генерация уменьшенных изображений товаров if (isset($GLOBALS['REQAR'][1]) && $GLOBALS['REQAR'][1] == 'new_resize_product_images') { $resize_all = false; if (isset($_POST['resize_all'])) { $resize_all = true; } $Images = new Images(); $response = $Images->resize($resize_all); if (isset($response['msg']) && !empty($response['msg'])) { foreach ($response['msg']['done'] as $key => $value) { if (!isset($str)) { $str = $key . ' - ' . $value; } else { $str .= ', ' . $key . ' - ' . $value; } } } else { $str = 'Ошибка'; } echo "<script>alert('Сгенерировано изображений: " . $str . "');</script>"; // echo "<script>alert('Сгенерировано изображений: 120x90 - ".$aa.", 250x250 - ".$ii.", 500x500 - ".$bb."');</script>"; } // /efiles/_thumb/image/
$width = 1000; $height = 1000 / $ratio; } else { if (max($size[0], $size[1]) == $size[1]) { $width = 1000 * $ratio; $height = 1000; } } } $res = imagecreatetruecolor($width, $height); imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255)); $src = $size['mime'] == 'image/jpeg' ? imagecreatefromjpeg($patch . $filename) : imagecreatefrompng($patch . $filename); imagecopyresampled($res, $src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); imagejpeg($res, $patch . $filename); } $Images->resize(false, $to_resize); $Products->UpdatePhoto($id, $images_arr, $_POST['images_visible']); if (isset($_POST['id_supplier'])) { //Формирем массив поставщиков товара for ($i = 0; $i < count($_POST['id_supplier']); $i++) { $supp_arr[] = array('id_assortiment' => isset($_POST['id_assortiment'][$i]) ? $_POST['id_assortiment'][$i] : false, 'id_supplier' => $_POST['id_supplier'][$i], 'price_opt_otpusk' => $_POST['price_opt_otpusk'][$i], 'price_mopt_otpusk' => $_POST['price_mopt_otpusk'][$i], 'product_limit' => $_POST['product_limit'][$i], 'inusd' => $_POST['inusd'][$i]); } foreach ($supp_arr as $k => $value) { if ($value['id_assortiment'] == false) { $value['id_product'] = $id; //Добавляем поставщика в ассортимент if (!$Products->AddToAssortWithAdm($value)) { echo '<script>alert("Ошибка при добавлении поставщика!\\nДанный товар уже имеется в ассортименте поставщика!");</script>'; } } else { //Обновляем данные в ассортименте
} if (isset($to_rename) && !empty($to_rename)) { foreach ($to_rename as $key => $value) { //$newname = $_POST['art'].'-'.(count($_POST['images'])-count($to_rename)+$i+1).'.jpg'; $newname = $_POST['art'] . '-' . ($i + 1) . '.jpg'; $file = pathinfo(str_replace('/' . str_replace($GLOBALS['PATH_root'], '', $GLOBALS['PATH_product_img']), '', $value)); $path = $GLOBALS['PATH_product_img'] . trim($file['dirname']) . '/'; if (is_dir($path) && file_exists($path . $file['basename'])) { rename($path . $file['basename'], $path . $newname); $_POST['images'][$key] = str_replace($GLOBALS['PATH_root'] . '..', '', $path . $newname); $i++; } $to_resize[] = $newname; } } $response = $Images->resize(false, $to_resize); } //Проверяем ширину и высоту загруженных изображений, и если какой-либо из показателей выше 1000px, уменяьшаем размер if (!empty($to_resize)) { foreach ($to_resize as $filename) { $size = getimagesize($path . $filename); //Получаем ширину, высоту, тип картинки if ($size[0] > 1000 || $size[1] > 1000) { $ratio = $size[0] / $size[1]; //коэфициент соотношения сторон //Определяем размеры нового изображения if (max($size[0], $size[1]) == $size[0]) { $width = 1000; $height = 1000 / $ratio; } else { if (max($size[0], $size[1]) == $size[1]) {