Tag Archives: image

PHP – Resize An Image

0
Filed under php
Tagged as , , , , , , , , ,

Author: slac3dork
site: http://snippet.c0de.me
summary: Php code to resize image. You need specify image path and name before run this code. Supported image extension: png, gif, jpg/jpeg, wbmp. Tested on Windows XP.

<?php 

/**
  _________      .__       .____   _______
 /   _____/ ____ |__|_____ |    |  \   _  \    ____
 \_____  \ /    \|  \____ \|    |  /  /_\  \  / ___\
 /        \   |  \  |  |_> >    |__\  \_/   \/ /_/  >
/_______  /___|  /__|   __/|_______ \_____  /\___  /
        \/     \/   |__|           \/     \//_____/  

http://snippet.c0de.me

slac3dork@gmail.com
*/

/**
* PHP Image Resize (PNG, JPG, GIF, WBMP)
* Coded By slac3dork
*/

$newwidth = 0;
$newheight = 0;
$ratio = 0;

// File and new size
$filename = 'example.jpg';

// Get new sizes
list($width, $height) = getimagesize($dest_file);

// Resize condition
if ($width > 600 || $height > 600) {
	$ratio = $width/$height;
	$newwidth = 550;
	$newheight = $newwidth/$ratio;
} else {
	$newwidth = $width;
	$newheight = $height;
}

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);

// get extension file
$file_ext_array = explode('.', $filename);
$file_ext = strtolower($file_ext_array[1]);

if (($file_ext = 'jpg') || ($file_ext = 'jpeg')) {
	$source = imagecreatefromjpeg($filename);
} elseif ($file_ext = 'gif') {
	$source = imagecreatefromgif($filename);
} elseif ($file_ext = 'png') {
	$source = imagecreatefrompng($filename);
} elseif ($file_ext = 'wbmp') {
	$source = imagecreatefromwbmp($filename);
} else {
	exit(1);
}

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
if (($file_ext = 'jpg') || ($file_ext = 'jpeg')) {
	imagejpeg($thumb, $filename.'_new.jpg');
} elseif ($file_ext = 'gif') {
	imagegif($thumb, $filename.'_new.gif');
} elseif ($file_ext = 'png') {
	imagepng($thumb, $filename.'_new.png');
} elseif ($file_ext = 'wbmp') {
	imagewbmp($thumb, $filename.'_new.wbmp');
} else {
	exit(1);
}

// delete old file
unlink ($filename);

?>



php,logo,pixel badge,badge

Javascript – Simple Image Slide Show

0
Filed under javascript
Tagged as , , , , , ,

Author: slac3dork
Site: http://snippet.c0de.me
Summary: A simple slide show image using javascript. You must define all your images path.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0.1//EN">
<html>
<head>
  <title>Simple Image Slide Show</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <script type="text/javascript">
/*
  _________      .__       .____   _______
 /   _____/ ____ |__|_____ |    |  \   _  \    ____
 \_____  \ /    \|  \____ \|    |  /  /_\  \  / ___\
 /        \   |  \  |  |_> >    |__\  \_/   \/ /_/  >
/_______  /___|  /__|   __/|_______ \_____  /\___  /
        \/     \/   |__|           \/     \//_____/  

http://snippet.c0de.me

slac3dork@gmail.com
*/
var i = 0;
var total = 5; // total slide show images
var t = 0;

function initial() {
	images[0] = 'path/to/images/1.jpg';
	images[1] = 'path/to/images/2.jpg';
	images[2] = 'path/to/images/3.jpg';
	images[3] = 'path/to/images/4.jpg';
	images[4] = 'path/to/images/5.jpg';
}

function timer() {
	clearTimeout(t);
	t = setTimeout('nextimg()', 3000);
}

function imageError() {
	nextimg();
}

function previmg(){
	if (i != 0){
		i = i - 1;
	} else {
		i = total;
	}
		document.banner_show.src = images[i];
}

function nextimg(){
	if (i != total){
		i = i + 1;
	} else {
		i = 0;
	}
	document.banner_show.src = images[i];
}
  </script>
</head>
<body>
  <img src="path/to/images/1.jpg" onLoad="initial();" onError="imageError" alt="" />
  <a onclick="previmg(); return false;">prev</a>
  <a onclick="nextimg(); return false;">next</a>
</body>
</html>

javascrip,logo,badge,pixel badge