Posted by: slvramesh on: June 15, 2011
PHP – Create thumbnail image
/** Common functions */
function make_thumb($name, $src, $dest, $new_w, $new_h) {
$border=false;
$transparency=true;
$base64=false;
if(!file_exists($src.DS.$name))
return false;
$arr = split("\.", $name);
$ext = strtolower($arr[count($arr)-1]);
if($ext=="jpeg" || $ext=="jpg"){
$img = @imagecreatefromjpeg($src.DS.$name);
} elseif($ext=="png"){
$img = @imagecreatefrompng($src.DS.$name);
} elseif($ext=="gif") {
$img = @imagecreatefromgif($src.DS.$name);
}
if(!$img)
return $name;
$old_x = imageSX($img);
$old_y = imageSY($img);
// proportionately - re-size image
/*
if($old_x < $new_w && $old_y $old_y) {
$thumb_w = $new_w;
$thumb_h = floor(($old_y*($new_h/$old_x)));
} elseif ($old_x < $old_y) {
$thumb_w = floor($old_x*($new_w/$old_y));
$thumb_h = $new_h;
} elseif ($old_x == $old_y) {
$thumb_w = $new_w;
$thumb_h = $new_h;
}*/
$thumb_w = $new_w;
$thumb_h = $new_h;
$thumb_w = ($thumb_w<1) ? 1 : $thumb_w;
$thumb_h = ($thumb_h= 0) {
//its transparent
$trnprt_color = imagecolorsforindex($img, $trnprt_indx);
$trnprt_indx = imagecolorallocate($new_img, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
imagefill($new_img, 0, 0, $trnprt_indx);
imagecolortransparent($new_img, $trnprt_indx);
}
}
else{
$white = imagecolorallocate($new_img, 255, 255, 255);
Imagefill($new_img, 0, 0, imagecolorallocate($new_img, 255, 255, 255));
imagefilledrectangle($new_img, 0, 0, $new_w, $new_h, $white);
}
} else {
$white = imagecolorallocate($new_img, 255, 255, 255);
Imagefill($new_img, 0, 0, imagecolorallocate($new_img, 255, 255, 255));
imagefilledrectangle($new_img, 0, 0, $thumb_w, $thumb_h, $white);
}
imagecopyresampled($new_img, $img, 0,0,0,0, $thumb_w, $thumb_h, $old_x, $old_y);
if($border) {
$black = imagecolorallocate($new_img, 0, 0, 0);
imagerectangle($new_img,0,0, $thumb_w, $thumb_h, $black);
}
$dest_filename = $arr[0].'_'.$new_w.'_'.$new_h.'.'.$ext;
$dest_filename = strtolower($dest_filename);
$dest_path = $dest.DS.$dest_filename;
if($base64) {
ob_start();
imagepng($new_img);
$img = ob_get_contents();
ob_end_clean();
$return = base64_encode($img);
} else {
if($ext=="jpeg" || $ext=="jpg"){
imagejpeg($new_img, $dest_path);
} elseif($ext=="png"){
imagepng($new_img, $dest_path);
} elseif($ext=="gif") {
imagegif($new_img, $dest_path);
}
}
imagedestroy($new_img);
imagedestroy($img);
//Delete the orginal file
if($src==$dest)
@unlink($src.DS.$name);
return $dest_filename;
}
Posted by: slvramesh on: September 1, 2010
When you going to add or edit path / menu in your site, it is necessary to check the menu are already taken by the site, other wise it will conflict.
When you create internal menu the drupal system automatically check with you site. but when you create external or via coding the below code will help to validate the path already taken or not.
All the internal or external menus are stored in the table “menu_router”.
/*
* Find the path is available
* Parameter menu path
* return TRUE if menu exists else return FALSE
*/
function is_path_exists($path) {
return (db_fetch_array(db_query("SELECT * FROM {menu_router} where path = '%s' ", $path))) ? TRUE : FALSE;
}
Posted by: slvramesh on: July 13, 2010
Drupal template system is very interesting because you can call any of page template as to your decided page. The following way you can call page template in drupal.
1) As per node or content type
2) As per menu
3) As per your argument in menu
The above three categories are covers your all drupal pages. So the following code will used to get template suggestion as per node or menu or argument.
/**
* Override or insert PHPTemplate variables into the templates.
*/
function phptemplate_preprocess_page(&$vars) {
// first, proceed with a modifed version of the standard
// Drupal template suggestion calls
$i = 0;
$suggestions = array();
$suggestion = 'page';
while ($arg = arg($i++)) {
$suggestions[] = $suggestion .'-'. $arg;
if (!is_numeric($arg)) {
$suggestion .= '-'. $arg;
}
}
if (drupal_is_front_page()) {
$suggestions[] = 'page-front';
}
// next, check for templates that use the path alias
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
if ($alias != $_GET['q']) {
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '-' . $path_part;
$suggestions[] = $template_filename;
}
}
$vars['template_files'] = $suggestions;
} // end path alias template check
if ($suggestions) {
$vars['template_files'] = $suggestions;
}
if (isset($vars['node'])) {
// When viewing a node focused as a full "page", it will suggest the node type.
// For example, a node type of "some_foo" will search for "page-some-foo.tpl.php".
$vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
}
}
The phptemplate_page_preprocess used to override drupal variables. The template file have been override the above code.
The same way you can user node template also.
Posted by: slvramesh on: June 22, 2010
The following code used to get sub-menu item of their parent menu.
Syntax:
$menu = menu_get_item(”);
Example:
$menu = menu_get_item('admin/store/export');
$content = system_admin_menu_block($menu);
$output = theme('admin_block_content', $content);
The above code get all the sub-menus under export parent menu.
Posted by: slvramesh on: May 28, 2010
I decided to keep on updating interview questions in this post. Because of hadling interview / attending interview in my previous company most of technical guys very strong in php coding and mysql etc. But no one update her/his small small technical knowledge even my self. So I will update my self and to you. Keep on view this post every week. I will update my knowledge this post. Do you have any question feel free just comment this post i will answer you.
Question 1: How to validate XHTML?
Answer: Before going to answer this question, i need to explain some of basic things in XHTML. I used Dreamweaver in windows, Aptana in Mac, Komodo in Linux. Those editors make default in document type, header and body tags. some of guys never take care about the document type because of the editors will handle. It is important one. Make sure what are the editors you are used and what are the default code placed when you create new html file. I hope every one should know about what is XHTML. Let see about How to validate XHTML.
The XHTML have Three doctype.
1. strict
2. transitional
3. frameset
Using above three doctype you can validate XHTML. For more information see How to validate XHTML
Question 2: What are the functions used to find Brwoser in AJAX?
Answer:
For getting IE7+, Firefox, Chrome, Opera, Safari browsers use the following code.
xmlhttp=new XMLHttpRequest();
For getting IE6, IE5 use the following code
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
Posted by: slvramesh on: May 10, 2010
Problem definition:
Drupal is the best CMS with building media related sites. Galleria is the best module for image gallery in drupal, the galleria module did not support caption when you use image filefield because the gallery module get caption for field description. When you use filefield it is support title and alt input field.
So here is the solution for getting caption for image in title tag.
1) In the content type manage fields enable alt and title tags.
2) Add the following coding in your galleria.module file function theme_galleria_formatter_imagefield_galleria end the “alt” text.
‘title’ => $element[$key]['#item']['data']['title']
3) Replace the coding in the function “template_preprocess_galleria”
$caption = ($image->title != $image->filename) ? $image->description : ”;
to
$caption = ($image->title != $image->filename) ? $image->title : ”;
Now view your galleria image gallery, caption will dispaly.
Cheers!
Posted by: slvramesh on: May 7, 2010
Menu breadcrumb has problem in views page. Having spend some times customized in template pages.
Add the below code in your template.php them file.
function phptemplate_preprocess_page(&$variables) {
$breadcrumb = drupal_set_breadcrumb();
if($breadcrumb[1]==”"){
$breadcrumb[1] = $variables["title"];
$variables['breadcrumb'] = theme(‘breadcrumb’, $breadcrumb);
}
}
Posted by: slvramesh on: March 29, 2010
HTML5 Forms have more features. Check his url http://snook.ca/archives/html_and_css/html5-forms-are-coming
Posted by: slvramesh on: November 9, 2009
I interested to looking beautiful websites because of my profession is developing quality websites. I think home page is most important for every website. If the visitor able to stay 3 minutes in your home page you site is good other wise you need to concentrate your home page.
The fantastic example for good home page is “Google Home page”.
Google homepage continues to maintain a bare minimum display of only 32 words, 19 links and 0 advertisement.
Why home page is important?
What are the things you satisfy in your home page?