Return to Snippet

Revision: 32176
at September 20, 2010 21:15 by simsevu


Updated Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
	
	$file_extension = end(explode(".", $inserted_product["image"]));	
		
	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;
	
	$bigger_image_size = getimagesize($image_source);
	$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) {
	$structure = explode("/", $path);
	$lastPath = '';
	
	foreach ($structure as $folder) {
		if ($lastPath) {
			$folder = $lastPath.'/'.$folder;
		}
		
		if (!is_dir($folder)) {
			mkdir($folder);
			chmod($folder, 0755);
		}
		
		$lastPath = $folder;
	}
}

Revision: 32175
at September 20, 2010 21:12 by simsevu


Updated Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
	
	$file_extension = end(explode(".", $inserted_product["image"]));	
		
	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;
	
	$bigger_image_size = getimagesize($image_source);
	$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) {
	$structure = explode("/", $path);
	$lastPath = '';
	
	foreach ($structure as $folder) {
		if ($lastPath) {
			$folder = $lastPath.'/'.$folder;
		}
		
		if (!is_dir($folder)) {
			mkdir($folder);
			chmod($folder, 0755);
		}
		
		$lastPath = $folder;
	}
}

Revision: 32174
at September 20, 2010 21:02 by simsevu


Updated Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
	
	$file_extension = end(explode(".", $inserted_product["image"]));	
		
	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;
	
	$bigger_image_size = getimagesize($image_source);
	$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
	
	$small_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_lille.jpg';
	$bigger_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$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);
}

Revision: 32173
at September 20, 2010 21:01 by simsevu


Updated Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
	
	$file_extension = end(explode(".", $inserted_product["image"]));	
		
	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;
	
	$bigger_image_size = getimagesize($image_source);
	$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
	
	$small_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_lille.jpg';
	$bigger_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_stor.jpg';
	
	$small_image = imagecreatetruecolor($widthSmall, $heightSmall);
	$bigger_image = imagecreatetruecolor($widthBigger, $heightBigger);
	
	imagecopyresized($small_image, $image_source, 0, 0, 0, 0, $widthSmall, $heightSmall, $width, $height);
	imagecopyresized($bigger_image, $image_source, 0, 0, 0, 0, $widthBigger, $heightBigger, $width, $height);

	imagejpeg($small_image, $small_path, $color_compression);
	imagejpeg($bigger_image, $bigger_path, $color_compression);
}

Revision: 32172
at September 20, 2010 20:56 by simsevu


Updated Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
		
	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;

	//Lav en version i 75px bred - Small
	//lav en version i 250px bred - Bigger
	$widthSmall = 75;
	$heightSmall = 60; // Crop bunden væk
	
	$bigger_image_size = getimagesize($image_source);
	$org_width = $bigger_image_size[0];
	$org_height = $bigger_image_size[1];
	
	$widthBigger = 250;
	$heightBigger = (250 / $org_width) * $org_height
	
	$image_split = explode(".", $inserted_product["image"]);
	$file_extension = $image_split[count($image_split)-1];
	
	$small_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_lille.jpg';
	$bigger_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_stor.jpg';
	
	$small_image = imagecreatetruecolor($widthSmall, $heightSmall);
	$bigger_image = imagecreatetruecolor($widthBigger, $heightBigger);
	
	imagecopyresized($small_image, $image_source, 0, 0, 0, 0, $widthSmall, $heightSmall, $width, $height);
	imagecopyresized($bigger_image, $image_source, 0, 0, 0, 0, $widthBigger, $heightBigger, $width, $height);

	imagejpeg($small_image, $small_path, $color_compression);
	imagejpeg($bigger_image, $bigger_path, $color_compression);
}

Revision: 32171
at September 20, 2010 20:49 by simsevu


Updated Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
	
	$color_compression = 65;

	//Lav en version i 75px bred - Small
	//lav en version i 250px bred - Bigger
	$widthSmall = 75;
	$heightSmall = 60; // Crop bunden væk
	
	$widthBigger = 250;
	$heightBigger = (250 / $org_width) * $org_height
	
	$image_split = explode(".", $inserted_product["image"]);
	$file_extension = $image_split[count($image_split)-1];
	
	$small_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_lille.jpg';
	$bigger_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_stor.jpg';
	
	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;
	}
	
	$small_image = imagecreatetruecolor($widthSmall, $heightSmall);
	$bigger_image = imagecreatetruecolor($widthBigger, $heightBigger);
	
	imagecopyresized($hvad_er_der_her, $hvad_er_der_her, 0, 0, 0, 0, $widthSmall, $heightSmall, $width, $height);
	imagecopyresized($hvad_er_der_her, $hvad_er_der_her, 0, 0, 0, 0, $widthBigger, $heightBigger, $width, $height);

	imagejpeg($small_image, $small_path, $color_compression);
	imagejpeg($bigger_image, $bigger_path, $color_compression);
}

Revision: 32170
at September 20, 2010 20:48 by simsevu


Updated Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
	
	$color_compression = 65;

	//Lav en version i 75px bred - Small
	//lav en version i 250px bred - Bigger
	$widthSmall = 75;
	$heightSmall = 60; // Crop bunden væk
	
	$widthBigger = 250;
	$heightBigger = (250 / $org_width) * $org_height
	
	$image_split = explode($inserted_product["image"]);
	$file_extension = $image_split[count($image_split)-1];
	
	$small_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_lille.jpg';
	$bigger_path = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_stor.jpg';
	
	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;
	}
	
	$small_image = imagecreatetruecolor($widthSmall, $heightSmall);
	$bigger_image = imagecreatetruecolor($widthBigger, $heightBigger);
	
	imagecopyresized($hvad_er_der_her, $hvad_er_der_her, 0, 0, 0, 0, $widthSmall, $heightSmall, $width, $height);
	imagecopyresized($hvad_er_der_her, $hvad_er_der_her, 0, 0, 0, 0, $widthBigger, $heightBigger, $width, $height);

	imagejpeg($small_image, $small_path, $color_compression);
	imagejpeg($bigger_image, $bigger_path, $color_compression);
}

Revision: 32169
at September 20, 2010 18:58 by simsevu


Updated Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
	$output_format = "jpg";

	//Lav en version i 75px bred - Small
	//lav en version i 250px bred - Bigger
	$widthSmall = 75;
	$heightSmall = 60; // Crop bunden væk
	
	$widthBigger = 250;
	$heightBigger = (250 / $org_width) * $org_height
	
	$color_compression = 65;
	
	//end path + filename
	$fileSmall_end = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_lille.jpg';
	$fileBigger_end = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_stor.jpg';

}

Revision: 32168
at September 20, 2010 18:58 by simsevu


Initial Code
function insert_image($inserted_product, $product_id){

	$image_url = $inserted_product["url"];
	$image_types = array("jpg", "jpeg", "png", "gif", "bmp");
	$output_format = "jpg";

	//Lav en version i 75px bred - Small
	//lav en version i 250px bred - Bigger
	$widthSmall = 75;
	$heightSmall = 60; // Crop bunden væk
	
	$widthBigger = 250;
	$heightBigger = (250 / $org_width) * $org_height
	
	$color_compression = 65;
	
	//end path + filename
	$fileSmall_end = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_lille.jpg';
	$fileBigger_end = '../shops/'.$inserted_product["shop_id"].'/products/'.$product_id.'/'.$inserted_product["slug"].'_stor.jpg';

}

Initial URL


Initial Description


Initial Title
image to server

Initial Tags


Initial Language
PHP