In my previous project i was using timthumb. But thumbnails are not working and when i direct call images it was giving 500 internal server error.
PHP GD library was enabled on the server. So the issue was because of the .htaccess file. So i deleted .htaccess file and changed file permission to 755 and the script worked.