Skip to content

Instantly share code, notes, and snippets.

@volandku
Created May 19, 2019 07:23
Show Gist options
  • Save volandku/a22e7897947e3ef696899638d947dbb9 to your computer and use it in GitHub Desktop.
Save volandku/a22e7897947e3ef696899638d947dbb9 to your computer and use it in GitHub Desktop.
uploadImage for JoomShopping (code)
require_once(__DIR__.'/../../../../../../components/com_jshopping/lib/image.lib.php');
use ImageLib;
// тут еще класс, вырвано из контекста
function uploadImage($url,$image_name)
{
// Блин у шоппинга не вижу такой стандартной функции, ну как так?
// Заливаем картинки и создаем миниатюры и прочее
$jshopConfig = JSFactory::getConfig();
$dispatcher = JDispatcher::getInstance();
$app = JFactory::getApplication();
$path_image = $jshopConfig->image_product_path."/".$image_name;
$path_thumb = $jshopConfig->image_product_path."/".'thumb_'.$image_name;
$path_full = $jshopConfig->image_product_path."/".'full_'.$image_name;
$contextOptionsArray = [ "ssl" => ["verify_peer" => false,"verify_peer_name" => false]];
$contextOptions=stream_context_create($contextOptionsArray);
// echo $path_image;
copy($url,$path_image,$contextOptions);
@chmod($jshopConfig->image_product_path."/".$image_name, 0777);
rename($path_image, $path_full);
// if (!$this->checkUploadImageMinSize($path_full)) игнорим пока эту проверку
if ($jshopConfig->image_product_original_width || $jshopConfig->image_product_original_height)
{
if (!ImageLib::resizeImageMagic($path_full, $jshopConfig->image_product_original_width,
$jshopConfig->image_product_original_height, $jshopConfig->image_cut, $jshopConfig->image_fill,
$path_full, $jshopConfig->image_quality, $jshopConfig->image_fill_color, $jshopConfig->image_interlace))
{
$this->log("error", "SaveProduct - Error create thumbnail ".$image_name);
}
}
$product_width_image = $jshopConfig->image_product_width;
$product_height_image = $jshopConfig->image_product_height;
if (!ImageLib::resizeImageMagic($path_full, $product_width_image, $product_height_image, $jshopConfig->image_cut,
$jshopConfig->image_fill, $path_thumb, $jshopConfig->image_quality,
$jshopConfig->image_fill_color, $jshopConfig->image_interlace))
{
$this->log("error", "SaveProduct - Error create thumbnail ".$image_name);
}
@chmod($path_thumb, 0777);
$product_full_width_image = $jshopConfig->image_product_full_width;
$product_full_height_image = $jshopConfig->image_product_full_height;
if (!ImageLib::resizeImageMagic($path_full, $product_full_width_image, $product_full_height_image,
$jshopConfig->image_cut, $jshopConfig->image_fill, $path_image, $jshopConfig->image_quality,
$jshopConfig->image_fill_color, $jshopConfig->image_interlace))
{
$this->log("error", "SaveProduct - Error create thumbnail ".$image_name);
}
@chmod($path_image, 0777);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment