Wednesday, September 22, 2010

get dpi of image in php

Hi to get the dpi of any image you can use the following code

php opening tag

function get_dpi($filename){

// open the file and read first 20 bytes.

$a = fopen($filename,’r');

$string = fread($a,20);

fclose($a);



// get the value of byte 14th up to 18th

$data = bin2hex(substr($string,14,4));

$x = substr($data,0,4);

$y = substr($data,4,4);

return array(hexdec($x),hexdec($y));

}

// sample, output the result:

print_r(get_dpi(‘demo_files/abc.png’));

php close tag

PHP website performance tricks

Hi All,
The following are few points that I just wanted to share with you all. These points are the basic that should be kept in mind and will increase site performance. HAPPY CODING

1. Don't use .htaccess
2. Lock all ports down
3. Stop ping
4. Cut Apache modules down to bare minimum required for security
5. Do not install all PHP modules
6. Benchmark code, workaround narrow code, cache everything.
7. If a ... COUNT(*) ... GROUP BY ... is killing you, just don't do it! Add some app layer logic to increment some counter in some PRIMARY KEY table instead and have instant access to your stats.
8. Use shared folders in PHP instead of putting files outside web root
9. Enable APC
10. Enable Memcached
11. Use Redis or something for sessions
12. Careful programming, do not use slow or insecure functions and do not use header variables
13. Do not connect to your db directly in your code
14. Be careful with long standing selects and updating in MyISAM in MySQL. Table locking can occur causing all other selects to queue and pile up until eventually you have server downtime.
15. Normalize your DB up to 3NF
16. how about stopping hot linking, caching, protecting files from being leeched, stopping viewing of directories.
17. If you have to use .htaccess it directly into Apache config
18. Use CDN
19. Use jmeter. It's a graphical server performance testing tool, for both static and dynamic resources (files or CGI, Servlets, Perl scripts).