Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Thursday, November 20, 2008

The ways to create thumbnail image by php with thumbnail generators.

Delicious 0
When you want to display an image into your web page, maybe you need to resize it, make it smaller than the original, such as the headline images, image which represents for a post...That's all images are called Thumbnail. I'll not say much about what thumbnail means in this entry, and not about how to make thumbnail image in PHP because it's just a common skill that everyone who works with PHP can not live without. I just want to show you same useful code to make thumbnail that you dont need to do any coding...and maybe some people not know about PHP can do that easily. That all usefull tools (i dont know i use "tool" here is correct or not, just let me call it "tool") below are Thumbnail Generators.

1. phpThumb()

phpThumb() uses the GD library to create thumbnails from images (JPEG, PNG, GIF, BMP, etc) on the fly.  ImageMagick is used wherever possible for speed. Basic functionality is available even if GD functions are not installed (as long as ImageMagick is installed). It supports almost image formats or any image format ImageMagick can read. The output are, too and even ICO format.

Images can be rotate, cropped. Output is antialiased into the alpha channel where appropriate when PNG output is selected. Quality can be auto-adjusted to fit a certain output byte size.

This script support a large number of filters can be applied. It's an excellent set of free PHP scripts which can process and generate thumbnails very easily.



2. Zubrag Thumbnail Creator / Generator

PHP Thumbnail Creator is designed to generate thumbnails from JPG, GIF, or PNG images. Script can save rendered thumbnail as file on your server or output it directly to the browser.  There're nothing special from this tools, it's just a normal thumbnail generator. It supports JPG, PNG, GIF image type but depends on GD2 library. You can customize default value from source code. Script can also help you if you need to show few thumbnails based on the same source image but in different sizes, when you cannot afford saving created thumbs on your server for some reason.



3. PHP Thumbnail generator with shadow


This one is simple, simple to use, but the main feature it supports is so amazing. It can drop soft shadows below the thumbnails. Because the simplified of this tool, it just support 2 image type: PNG and JPG. PNG transparency is allowed, but when IE Browser is not version 7 or above, it will be detected and convert to JPG format instead. Absolutely, it can save the images in server in cache folder like others can do.




4. TimThumb PHP Script of Tim McDaniels

Just a simple script but is the most useful tool people using. Make a thumbnail, crop size or not and the quality of output. Main feature is users dont have to do nothing, if users want to crop the image, it will automatically crop width size if width size is larger than the height or do the same with height. This tool is the most popular tool to create thumbnail image by Wordpress users. It's supports cache, too.

Support: JPG, PNG (Resize a PNG with transparency and you'll get a white background), GIF (Reducing a GIF in quality will discard the transparency of the image, resulting in a black background)



5. Drop Shadowed Thumbnail Creator

This class allows you to very easily create thumbnails of images, on which you can also apply a drop-shadow effect. You can control the colour of the background so that drop-shadow will fit better onto your page and the size of the thumbnail.

You can resize in an absolute or relative way (to a certain size or by a certain size), both as a pixel number or a percentage.



6. jQuery easyThumb


jQuery easyThumb is a plugin for jQuery. The easy description is that it turns a list of full-scale images to a list of thumbnails on-the-fly. It uses a php-script to return a thumbnail for each image, and jQuery to generate the list. Let’s jump right to the installation.

Maybe you cant access the homepage because he is now hosting this script in a stupid host. Let try again later or try google with "jQuery easyThumb", you can find some useful informations about this script.




Final words:

These all tools above is just make us feel quickly when working. If you are a web developer, you can download and add some function to. Because of creating thumbnail in PHP with GD library support is just a common skill with php programmer, so if you are new to PHP, want to work with image, you should take a look at GD Functions in php manual page.


Bonus:

Friday, October 24, 2008

5 Useful tools to convert your entire code into Colorized and browsable HTML

Delicious 0
When you open your blog for sharing code, writing programming tutorial, publish a entry about codes, you should colorize, it called convert the entire code into colorized and make browsable with HTML. There are so many ways to do that, you can copy the code into web page design program and make up your code, but you don't know what're the easy ways to do that thing.

 1- Use syntaxhighlighter:

This tool base on java script and stylesheet, the most popular Syntax Highlight tool in the internet, WordPress is now using this tool to highligh the code embebed.
Homepage: SyntaxHighlighter in Google Code
Download: syntaxhighlighter
Usage: manual

I like this tool because it will automatic convert the code after the web browser loaded. Because that, the code will not be formated and you can edit it later easily.

It support so many language: PHP, SQL Query, Java, Python, C# .....It's cool, right?


2- Using PHP's Built-in Source Highlighter:

PHP offer two functions for highlighting PHP code: highlight_file() and highlight_string(). Both functions return the same results, but each has its own specific input parameters. As their names suggest, the first function takes the filename of the PHP script whose code is to be highlighted, while the second takes the input as a string.

A Quick Example
Let's take a look at an example of the highlight_string() function in action:

<?php 
include_once 'init.inc.php'; 

if (!empty($_POST['text'])){ 
   echo '<div style="border: solid 1px orange; padding: 20px; margin: 20px">'; 
   highlight_string($_POST['text']); 
   echo '</div>'; 
} 
?> 



<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> 
   <textarea name="text" style="width: 300px; height: 200px"><?php 
       echo @$_POST['text'];  
   ?></textarea> 
   <br /> 
   <input type="submit" /> 
</form>


This script displays a simple textbox into which you can type or paste the PHP code you want to highlight.



3- Java2HTML Converter (for java blog): 

This is also cool converter. Java2Html was write with java language, it converts Java (and other) source code (complete files or snippets) to HTML, RTF, TeX and XHTML with syntax highlighting.
Homepage: Java2HTML Converter
Download: download here

Java2HTML can be used as Eclipse plugin and it's useful for fastly convert in time.

However, after converted, the code will be formated and it'll hardly to edit later if you want to updated your entry.



4- CodeColorizer: Free Tool to Colorize Code in HTML or RTF.

This application allows you to generate HTML or RTF so you can colorize:
  • C#, VB.NET, J#, Javascript, Cobol, Algol
  • HTML, XML, XSLT, .Config
  • T-SQL
  • CSS, and many more...
Homepage: CodeColorizer
Download: download here
Things to notice is that it generates the simplest Html possible to achieve the right formatting. It colorizes in the same place ASP.NET code, HTML, C# code, javascript code, CSS styles, and more...



5-Csharpfriends.com Online Code Formatting:

Online site formatting with following code: C#, VB.NET, J# and T-SQL.
Its useful for who dont want to install any program into computer and dont need to add any code into webpage to do automaticlly, you just do it online, copy and go back to your working
Link to converter: CSharpfriend Online Code Fomartting

If you found some webpages or tools can do something like that, please correct me. Pleased to make you work perfectly.

Sunday, October 19, 2008

Selecting random record from MySQL database table.

Delicious 0
There are so many solution to select random record from MySQL table by using rand(). But we should have to know what solution is the simple and best executing. I found this post from Akinas Blog.

Solution 1 [SQL]: The slowest method is solution 1. Let's say that it took 100% of time to execute.


SELECT * FROM `table` ORDER BY RAND() LIMIT 0,1;

Solution 2 [using with PHP]: took 79%.
$range_result = mysql_query( " SELECT MAX(`id`) AS max_id , MIN(`id`) AS min_id FROM `table` ");
$range_row = mysql_fetch_object( $range_result );
$random = mt_rand( $range_row->min_id , $range_row->max_id );
$result = mysql_query( " SELECT * FROM `table` WHERE `id` >= $random LIMIT 0,1 "); 


Solution 3 [using with PHP]: took 13%.
$offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `table` ");
$offset_row = mysql_fetch_object( $offset_result );
$offset = $offset_row->offset;
$result = mysql_query( " SELECT * FROM `table` LIMIT $offset, 1 " ); 


Solution 4 [SQL]; took 16%
SELECT * FROM `table` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` ) ORDER BY id LIMIT 1;

You can see what different between these solutions from Akinas Blog.