/ Published in: PHP
Expand |
Embed | Plain Text
function insert_image($inserted_product, $product_id){ $image_url = $inserted_product["url"]; switch($file_extension){ case "jpeg": $image_source = imagecreatefromjpeg($image_url); break; case "jpg": $image_source = imagecreatefromjpeg($image_url); break; case "gif": $image_source = imagecreatefromgif($image_url); break; case "png": $image_source = imagecreatefrompng($image_url); break; case "bmp": $image_source = imagecreate($image_url); break; } $color_compression = 65; $org_width = $bigger_image_size[0]; $org_height = $bigger_image_size[1]; $widthSmall = 75; $heightSmall = ($widthSmall / $org_width) * $org_height; $widthBigger = 250; $heightBigger = ($widthBigger / $org_width) * $org_height; $dir = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'; create_folder($dir); $small_path = $dir.$inserted_product["slug"].'_lille.jpg'; $bigger_path = $dir.$inserted_product["slug"].'_stor.jpg'; $small_image = imagecreatetruecolor($widthSmall, $heightSmall); $bigger_image = imagecreatetruecolor($widthBigger, $heightBigger); imagecopyresampled($small_image, $image_source, 0, 0, 0, 0, $widthSmall, $heightSmall, $org_width, $org_height); imagecopyresized($bigger_image, $image_source, 0, 0, 0, 0, $widthBigger, $heightBigger, $org_width, $org_height); imagejpeg($small_image, $small_path, $color_compression); imagejpeg($bigger_image, $bigger_path, $color_compression); } function create_folder($path) { $lastPath = ''; foreach ($structure as $folder) { if ($lastPath) { $folder = $lastPath.'/'.$folder; } } $lastPath = $folder; } }
You need to login to post a comment.
