<?php
/*
ImageThumb - Creates a thumbnail image from another based on specified sizes
SourceImage - The location of the image in which you want to resize
DestImage - The location to save the thumb, use null if you want to just display to browser
Width - The resized width of the image
Height - The resized height of the image
Type - The image type in which you want to save
Note: The thumb is resized while keeping the aspect ratio, so width and height are not the
absolute width and height.
*/
function ImageThumb($sourceImage, $destImage, $width, $height, $type = "png") {
$type = strtolower($type);
$imageSize = getimagesize($sourceImage);
if($imageSize[0] > $imageSize[1]) {
$newWidth = $width;
$newHeight = $imageSize[1] * ($newWidth / $imageSize[0]);
}
else {
$newHeight = $height;
$newWidth = $imageSize[0] * ($newHeight / $imageSize[1]);
}
switch(image_type_to_mime_type($imageSize[2])) {
case "image/jpeg":
$image = imagecreatefromjpeg($sourceImage);
break;
case "image/gif":
$image = imagecreatefromgif($sourceImage);
break;
case "image/png":
$image = imagecreatefrompng($sourceImage);
break;
default:
$t = image_type_to_mime_type($imageSize[2]);
echo "The file type {$t} is not supported, please use either jpeg, gif, or png";
break;
}
$thumb = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $newWidth, $newHeight, $imageSize[0], $imageSize[1]);
switch($type) {
case "jpg":
case "jpeg":
header("Content-type: image/jpeg");
imagejpeg($thumb, $destImage);
break;
case "gif":
header("Content-type: image/gif");
imagegif($thumb, $destImage);
break;
case "png":
header("Content-type: image/png");
imagepng($thumb, $destImage);
break;
default:
echo "The image type {$type} is not supported, please choose another.";
break;
}
imagedestroy($image);
imagedestroy($thumb);
}
?>
Tag Archive for image
Resize Image
Quickly resize images in command line (requires ImageMagick)
convert -resize WIDTHxHEIGHT source.jpg target.png
image viewer
<link rel="stylesheet" href="thumbnailviewer.css" type="text/css" /> <script src="thumbnailviewer.js" type="text/javascript"> /*********************************************** * Image Thumbnail Viewer Script- © Dynamic Drive (www.dynamicdrive.com) * This notice must stay intact for legal use. * Visit <a href="http://www.dynamicdrive.com/" >http://www.dynamicdrive.com/</a> for full source code ***********************************************/ </script> <!-- in the head, plus a couple separate files at the URL --> <!-- in the body --> <p><a href="http://img184.imageshack.us/img184/1159/castleyi6.gif" rel="thumbnail" title="This is beautiful castle for sale!">Castle</a></p> <p><a href="http://img201.imageshack.us/img201/6923/countryxb6.gif"" rel="thumbnail"><img src="thumbnail.gif" style="width: 50px; height: 50px" /></a></p>
CSS PNG Image Fix for IE
* html img,
* html .png{
azimuth: expression(
this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')",
this.src = "/style/images/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')",
this.runtimeStyle.backgroundImage = "none")),this.pngSet=true
);
}
________
________
Also consider adding this conditional comment on your HTML page
________
________
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="png_fix.css" />
<![endif]--
Replacing autoscroll image in Firefox
html>img /* autoscroll override for Firefox */
{
width: 0!important;
height: 28px!important;
padding-left: 28px!important;
background: url(/images/icons/autoscroll2.png);
}
Image Replace for Buttons
#submitButton {
width: 38px;/* Width of button image */
height: 19px;/* Height of button image */
padding: 30px 0 0;
margin: 0;
border: 0;
background: transparent url(images/buttonimage.gif) no-repeat;
overflow: hidden;
cursor: pointer; /* hand-shaped cursor */
cursor: hand; /* for IE 5.x */
}
Images preloader
var images = new Array();
function preloadImages(){
for (i=0; i < preloadImages.arguments.length; i++){
images[i] = new Image();
images[i].src = preloadImages.arguments[i];
}
}
preloadImages("logo.jpg", "main_bg.jpg", "body_bg.jpg", "header_bg.jpg");
Image Align
img.centered {
display: block;
margin-left: auto;
margin-right: auto;
}
img.alignright {
padding: 4px;
margin: 0 0 2px 7px;
display: inline;
}
img.alignleft {
padding: 4px;
margin: 0 7px 2px 0;
display: inline;
}
.alignright {
float: right;
}
.alignleft {
float: left
}
Turning a dmg into an iso
1) Open a terminal. 2) cd into the directory where the dmg is located 3) Type this in (where newfile is the name of the iso you want, and yourfilename.dmg is the dmg) hdiutil makehybrid -iso -o newfile.iso yourfilename.dmg
Base64 encode
perl -MMIME::Base64 -e' open(FILE, $ARGV[0]) or die "$!";while (read(FILE, $buf, 60*57)) {print encode_base64($buf);}'