Use a PHP library installed on the website server.
Phpqrcode is a full PHP library :

Implemented purely in PHP, with no external dependencies (except GD2 if needed).

I tweak the Mobile Codes in order to use it and it works fine. I also use the Libraries API module.

Comments

newToo’s picture

Can you share the tweaked Mobile Codes code?

Anonymous’s picture

OK.

I'll try to find some time this week end.

newToo’s picture

Thanks!

Anonymous’s picture

  1. I use libraries module in order to centralize external libraries : http://drupal.org/project/libraries
    This is not mandatory.
  2. Download phpqrcode : http://phpqrcode.sourceforge.net/
  3. De-archive phpqrcode and install it in desired location. In my case : /sites/all/libraries/.
  4. Now you have all the phpqrcode code in : /sites/all/libraries/phpqrcode
  5. Replace mobile_codes_generate function in mobile_codes/mobile_codes.module by the code below.
    The call to Nokia webservice is commented and replaced by phpqrcode generation.
  6. In mobile_codes/mobile_codes.module

    /**
     * Generate a mobile code
     */
    function mobile_codes_generate($data, &$arguments = array()) {
      $values = mobile_codes_process_arguments($arguments);
      if (($file = mobile_codes_load_mobile_code($data, $arguments)) === FALSE) {
    
        $dir = '/mobile_codes/'. $arguments['preset'];
        $file = file_directory_path() . $dir .'/'. time() . rand(1000, 9999) .'.png';
    
        if ($arguments['data'] == 'link' && ($arguments['tinyurl'] == 1 || drupal_strlen($data) > 60)) {
          $headers = array('Content-type' => 'application/x-www-form-urlencoded');
          $tinyurl = drupal_http_request('http://tinyurl.com/api-create.php?url='. urlencode($data), $headers, 'POST', NULL);
          if ($tinyurl->code == 200) {
            $data = $tinyurl->data;
          }
        }
    
    
          
    /*
        $url = 'http://mobilecodes.nokia.com/'. $arguments['type'] .'?'. $values['text']['data'] .'='.
          urlencode($data) .'&'. $values['text']['size'] .'='. $values['size'][$arguments['type']]
          .'&name='. $arguments['name'] . $values['text']['margin_encoding'] .'&type='. $arguments['data']
          .'&MODE='. $values['mode'] .'&a=create';
        mobile_codes_directory_check($dir);
        $image = drupal_http_request($url);
        //file_save_data($image->data, $file, FILE_EXISTS_REPLACE);
     */
     
     
       // QR Code Configuration
       $QRCodeConfig = array();
       // Level of error correction
       // (one form: L,M,Q,H)
       $QRCodeConfig['ECC'] = 'L';
       
       // Code square size in pixels.ie : 4, 4x4 (4x zoom)
       $QRCodeConfig['Square size'] = 8;
       
       // Code outerFrame in pixels (white boundary around) 
       $QRCodeConfig['Outer Frame'] = 2;
       
       
       mobile_codes_directory_check($dir);
       
       // Insert phpqrcode using libraries module
       include_once (libraries_get_path('phpqrcode/qrlib.php'));
       
       
       // Create QRCode
       QRcode::png( $data,
                    $file,
                    $QRCodeConfig['ECC'],
                    $QRCodeConfig['Square size'],
                    $QRCodeConfig['Outer Frame']);
    
        mobile_codes_save_mobile_code($data, $arguments, $file);
      }
    
      return $file;
    }
    

    Hope this work for you.

newToo’s picture

Thank you very much! I'm going to try it today.

newToo’s picture

Works great! Thanks again.

I do have a somewhat related question to this module and I was wondering if you knew. I'm trying to create an inventory system where the qr code points to a node. So basically a user would create a node and the url of that node would be embedded in the qr code on the fly. The problem I'm having is getting the node url to insert itself into a field in a node so that mobile codes can read it and create the qr code. I hope this makes sense.

Anonymous’s picture

I've done the same stuff you need !

Here is the source code added on a module especially created for the project.
The project is called tazas which is spanish word for english word cups. So the module is called tazas.

I add 3 functions :

  1. tazas_nodeapi, to add data to the node
  2. tazas_theme, to apply theme
  3. theme_tazas_qrcode, to create the output

Here is the code :

/**
 * Implementation of hook_nodeapi().
 */

function tazas_nodeapi(&$node, $op,$teaser, $page) {

  global $user;
  
  switch($op):
    case 'view':
      // Abort if the user is an anonymous user (not logged in) or
      // if the node is not being displayed on a page by itself
      // (for example, it could be in a node listing or search result).
      if ($user->uid == 0 || !$page):
        break;
      endif;
      
      // Find out which node types we should generate QR code for.     
      $types_to_generate_QR_code = variable_get('tazas_node_types', array());

      // Abort if this node is not one of the types we should annotate.
      if (!in_array($node->type,$types_to_generate_QR_code,true)):
        break;
      else:
      
      $node->content['QR_Code'] = array('#value' => theme('tazas_qrcode', $node),
                                        '#weight' => 2 );
      endif;
  endswitch;
  
}

/**
 * Implementation of hook_theme().
 */
function tazas_theme() {
  return array('tazas_qrcode' => array( 'arguments' => array('node'),), );
}

/**
 * Create HTML for QR code.
 */
function theme_tazas_qrcode($node) {
  global $base_url;
  $node_alias = $base_url.url("node/$node->nid");
  $output = '<div class="tazas-qrcode">'."\n"
            .'<p>'.$node_alias.'</p>'."\n"
            .theme('mobilecode', $node_alias, array('preset' => 'default'))."\n"
            .'</div>';
            
  return $output;
}

Guess you can find a better and thinner solution ! This is a quick answer I wrote with lack of knowledges on certain Drupal area.
Feel free to feedback remarks !

newToo’s picture

Thank you! I will give it a try.

newToo’s picture

Did you add this to the Mobile Codes module and rename the module, or did you create a new module? I'm not sure how to implement this. Do I create a new content type for "tazas" (for testing)? Thanks for your help.

Anonymous’s picture

You have to create a new module.
Do not create a content type for testing

You could in a first try comment the node type evaluation code. The function tazas_nodeapi is then :

/**
* Implementation of hook_nodeapi().
*/

function tazas_nodeapi(&$node, $op,$teaser, $page) {

  global $user;
  
  switch($op):
    case 'view':
      // Abort if the user is an anonymous user (not logged in) or
      // if the node is not being displayed on a page by itself
      // (for example, it could be in a node listing or search result).
      if ($user->uid == 0 || !$page):
        break;
      endif;
      
      $node->content['QR_Code'] = array('#value' => theme('tazas_qrcode', $node),
                                        '#weight' => 2 );
  endswitch;
  
}

or even thinner with no display condition :

function tazas_nodeapi(&$node, $op,$teaser, $page) {
  
  switch($op):
    case 'view':

      $node->content['QR_Code'] = array('#value' => theme('tazas_qrcode', $node),
                                        '#weight' => 2 );
  endswitch;
  
}

The Mobile Codes module is well build so you can read the code and the comments to learn more about how to realize specific things.

newToo’s picture

I'll try it, thanks... Would I create a field called "QR_Code" in an existing page content type? I'm just not getting where the data will be stored and retrieved my mobile codes to create the qr code.

Anonymous’s picture

Mobile Codes module store QR_Code pictures in files/mobile_codes directory : when asking to display QR_Code it determines whether it have to generate a new file or display an existing one.

To retrieve this picture you only have to use theme function for Mobile Codes module with the current node alias :

   global $base_url;

   # compute node alias
   $node_alias = $base_url.url("node/$node->nid");  

   # render QR Code
   print theme('mobilecode', $node_alias, array('preset' => 'default'));
newToo’s picture

Thanks Domsou... I've found a module which should allow me to use tokens to create the url for Mobile Codes. It's called Link (http://drupal.org/project/link) So basically I would need to figure out how to use this module with the same field types Mobile Codes use so Mobile Codes can create the qr code. :) I think.

Anonymous’s picture

If I well understand your needs, I think module Link is useless as QR_code is generated using node alias data. If you want to have some automatic URL alias creation I then recommend using Path Auto module.
If you want to retrieve QR_Code image from node, you can use Mobile Codes API to do this.

You can also create a specific content type for QR_Code representing a specific URL. In this case you can use CCK field to reference a node (and then it's alias you need to build QR Code).

Or maybe I do not understand your need ! In my case it was the following : generate QR_CODE for content node linking. Let's say I create a book page : the QR Code representing the page URL is generated and displayed to specific user which then can copy it and add it to whatever print media desired (flyer, poster, CV...).

I realize we are out of the scope of this issue : use phpqrcode library.
So if you want to continue this discussion I suggest you open a support request ticket.

newToo’s picture

Thank you for your suggestions! I am using pathauto to create the node alias, and all of that is working correctly. I'm using Token to get the node alias into Mobile Codes and the image is being created. But the one problem I'm having is with Views, once I want to use the field that contains the url information that generates the qr code, it stops after the "/" in the url and produces a new qr code for the domain only.

So to clarify.

The CCK field produces a qr code that leads to: http://example.com/2232 - that's what i want.

But when brought over into views a new qr code is created for: http://example.com/

Everything after the slash is dropped, so the url alias is missing only on the view. It's weird, it's as if Mobile Codes produces a new qr code everytime the node is accessed.

I too realize this is beyond the scope of this disscusion, i just wanted to complete this thought.

Thank you so much for all of your help.

Anonymous’s picture

Please, open a support ticket in Mobiles Codes and add the link to this ticket in this thread.
Since #12 we are beyond the scope !

newToo’s picture

I've created a new support ticket for the Views issue (http://drupal.org/node/791794).

Deciphered’s picture

Support for PHP QR Code library coming to 6.x-2.x. It won't be dependent, but if the Libraries module is enabled and the Library is present it will be available as a Provider.

Deciphered’s picture

Status: Active » Fixed

Committed to https://github.com/Decipher/mobile_codes (will be moved over to D.o. when ready for release).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

newnewuser’s picture

subscribe

lameei’s picture

have done everything said on the readme file for adding the "phpqrcode" but it is not shown on the "providers" list. Am i missing something?