PHP convert none png image to png format using GD

September 25, 2014

Based on what kind of image it is you could select the correct function to open the file. Then, you just need imagepng() to convert. Example:

PHP resize image using ratio

September 25, 2014

To maintain the aspect ratio of your original image, calculate the factor by which you have to resize the image in the vertical and horizontal direction. Example, resize image to 1920 max width or max height

PHP get image width & height

September 25, 2014

To get the width and height of the image use getimagesize(path_name), this function returns the array which contains the height, width, image_type constant and other image related info. By the following code you can achive that. See also PHP resize image using ratio

Eclipse auto indent, auto formatting, auto alignment shortcut

September 25, 2014

Ctrl+Shift+F to invoke the Auto Formatter Ctrl+I to indent the selected part (or all) of you code. To format it automatically when you save the file, then Goto Window > Preferences > Java > Editor > Save Actions and configure your save actions. Along with saving, you can format, Organize imports,add modifier ‘final’ where possible […]

Ubuntu install PHPMyAdmin

September 18, 2014

  Type the following line in terminal: #sudo apt-get install phpmyadmin Package configuration – when asked which web server to use, select apache or lighthttpd – When asked “Configure database for phpmyadmin with dbconfig-common”? Choose “Yes” – Next key in “Password of the database’s administrative user:”. This is password for MySQL that you set during […]

Linux how to exit man page

September 18, 2014

After finished reading a man page manual, press “q” on your keyboard to quite or exit the page. Linux manual pages can be easily accessed via the terminal by typing man program-name. Manual or info page navigation can be accomplished by using the up and down arrow keys or in some cases, by pressing enter for more Once your finished viewing a […]

GIT remote show origin

September 15, 2014

git remote show origin displays info for your remote origin repo. I typically use this when I want to get the URL or the remote repo $ git remote show origin * remote origin Fetch URL: Push URL: HEAD branch: master Remote branches: iss1903_microsite tracked iss1907_baidu_staticmap tracked iss1910_retailer_map_pic tracked master tracked Local branch […]

PHP delete file in directory

September 15, 2014

If to delete a single file, use the unlink() function. Unlink can safely remove a single file. That function will delete what you pass it as a parameter. For example, delete single file Delete multiple file in a directory, use loop:

PHP check if image file exists

September 12, 2014

File_exists does something weird, it does not say if a file exists, it says if path exists. So, to check if it is a file then you should use is_file together with file_exists to know if there is really a file behind the path, otherwise file_exists will return true for any existing path. Example:

PHP MySql query for random record from database table

September 5, 2014

The simplest way of selecting random rows from the MySQL database is to use “ORDER BY RAND()” clause in the query. Example: