This function simply removes the form:


function avatarcrop_form_alter(&$form, &$form_state, $form_id) {

if ($form_id == 'user_profile_form') {
/*	$base=base_path();	
	$form['picture']['picture_upload'] = array(
		'#value' => '<a href="'.$base.'user/getimage" class="avatar-crop-picture">'. 'Upload picture' .'</a>',
	);*/
	$form['picture']=array();
	
   		
  }
}

If I correct the function by removing the comment and inverting the lines, I see a link to a form but upload fails with a jpg.

No explicit error message are given.

Comments

magoo’s picture

btw: the String should be localisable t().

Babalu’s picture

can you please make a patch that this module works
or type the correct code here

magoo’s picture

I haven't tried to make it work more than finding why the form did not appear.

Uncommenting the commented part and commenting the "=array()" assignement will make the link appear but the upload will not work...

btw:

the link should be replaced by the url function!

mstef’s picture

+1 - does not work at all

oops

mzi’s picture

just pushing it up.

changed my way from cck_imagefield to built in user picture and now i would really enjoy this avatarcrop!

ghiley’s picture

I have just installed Avatar Crop and (as this issue suggests) I am not getting anything on add user or edit user pages. Furthermore, by enabling Avatar Crop the default Drupal 'picture support' for profiles is removed.

Any ideas?

v8powerage’s picture

This module should be renamed Avatar Crap

betoaveiga’s picture

Doesn't work for me too.

The solution, IMO, not so nice but still a solution, is to use panels, and a crop image module (ImageField Crop), and use the resulting cropped image as the profile image. Modules like form defaults & profile content could help to make everything looks consistent.

Also... I don't know how to do it but for sure there's a way to change the user picture when uploading another picture, then users will get the cropped picture script working & content like comments, nodes, etc will show the cropped avatar.

Actually the ImageField Crop dev & stable versions have problems with IE8 & even FF, at least in my case. However these modules seems to be a lot more better & serious than Avatar Crop.

adeel.iqbal’s picture

Hi,

What can i say it wasn't working for me in start too but now it is completely working for me as i spent some time and made some changes to it. I think the main reason behind not working is lack of user documentation.

I am going to share my solution here. What my solution does is show an "Upload picture" link in user account edit page instead of upload picture field. when you click to it you will go to another page for picture upload then next to image crop page and then you submit and get back to your account edit page.

Now how to make it work. I am gonna be bit brief.

Step-1: Make sure you have user picture settings done in User settings. like you have enabled picture support as well as you have set "Picture maximum dimensions" value.

Step-2: In second step you have to edit "avatarcrop.module" file. go to folder and open the mentioned file for editing. Find at the end of file

function avatarcrop_form_alter(&$form, &$form_state, $form_id) {

if ($form_id == 'user_profile_form') {
/*	$base=base_path();	
	$form['picture']['picture_upload'] = array(
		'#value' => '<a href="'.$base.'user/getimage" class="avatar-crop-picture">'. 'Upload picture' .'</a>',
	);*/
	$form['picture']=array();
	
   		
  }
}	

and REPLACE it or CHANGE it to

function avatarcrop_form_alter(&$form, &$form_state, $form_id) {

if ($form_id == 'user_profile_form') {
	$base=base_path();	
	$form['picture']['picture_upload'] = array(
		'#value' => "'<a href="'.$base.'user/getimage" class="avatar-crop-picture">'. 'Upload picture' .'</a>'",
	);
  }
}

This will show "Upload picture" link in you user edit form.

Step-3: In this step Find "function cropUserPic_submit($form, &$form_state)" in same avatarcrop.module file, a few lines above where the step-2 function added and go to its last line

Find:

  drupal_goto('user/'.$user->uid); 

And Change it to:

drupal_goto('user/'.$user->uid.'/edit');

This will get you back to account edit page.

Step-4: To make it work for IE versions please visit http://drupal.org/node/564178

changing avatarcrop/avatarcrop.js
Change from this

onSelect: showCoords,

to this (Remove the comma)

onSelect: showCoords

worked for me.

Though it is not complete but I appereciate the effort of Avatar Crop module owner "sourcen" & IE fixer "animelion" ;)

Hope this will be helpful.

newitt’s picture

Thank you, thank you. This worked great! The only difference I did as when I added this code:

function avatarcrop_form_alter(&$form, &$form_state, $form_id) {

if ($form_id == 'user_profile_form') {
$base=base_path();
$form['picture']['picture_upload'] = array(
'#value' => "'<a href="'.$base.'user/getimage" class="avatar-crop-picture">'. 'Upload picture' .'</a>'",
);
}
}
my whole site went missing, however it was only because it needed to be '#value' => "''. 'Upload picture' .''",

Thank you again

adeel.iqbal’s picture

My pleasure ;)

newitt’s picture

I just have one issue with avatar crop. It all works great, however after I crop it and it returns to the edit page. I need to hit refresh on the edit page again to see the cropped pic. The large image shows by default. But it is actually cropped? Any ideas?

newitt’s picture

It is ok, I found the answer here:
http://drupal.org/node/506360

pixelsweatshop’s picture

This seems like such a simple fix. Are you able to apply this to a new release, so us noobs don't have to go in and edit the module?

adeel.iqbal’s picture

StatusFileSize
new5.11 KB
new496 bytes

@nigel.waters i don't know who you are asking to do it :) . I think 'sourcen' the creator of this module is inactive since it's 1.1 release.
anyhow I'll try to get the cvs account to put this fix in release of the module. Meanwhile i have created full patch that fixes almost all of the avatarcrop module problems.

Full Patch.

Babalu’s picture

works great for me with the patches :)

adeel.iqbal’s picture

That's good ;)..

Subscribe here if you want these patches to be integrated in the module.

Babalu’s picture

please include the patches
i'm using the avatar selection module. can you integrate a avatar delete button to avatar crop ? maybe in a avatar crop settings section to activate or deactivate this button.
i'm missing the delete button after enabling the avatar selection module

adeel.iqbal’s picture

StatusFileSize
new5.07 KB

To enable delete option just comment or remove the following line of code from 'function avatarcrop_form_alter(......)' in 'avartcrop.module'.

$form['picture']['picture_delete']= array();

OR

you can use this new patch instead of the patch given in "#5" .

adeel.iqbal’s picture

Subscribe here if you want these patches to be integrated in module ;)

Babalu’s picture

hmm i can't save the attached patch

adeel.iqbal’s picture

StatusFileSize
new5.07 KB

hmmm i can see that the patch in #19 can't be opened or downloaded might be extension problem. so uploading again. New and Fresh version of patch ;)
This should work fine now.

gitin’s picture

thanx for this module and patch...u guys rock
and for those who don't know, how to apply the patch
they can copy this whole code and replace (select all, then delete and paste) into original avatarcrop.module file using appropriate editor and it will work
thanx
<?php

function avatarcrop_perm() {
return array('Avatar crop');
}
function avatarcrop_init() {

$dimension=variable_get('user_picture_dimensions','100x100');
$widthXheight=split('x',$dimension);
$width = $widthXheight[0];
$height = $widthXheight[1];

drupal_add_js('var cwidth = '. $width .';','inline');
drupal_add_js('var cheight = '.$height.';','inline');

drupal_add_js(drupal_get_path('module','avatarcrop').'/avatarcrop.js');
drupal_add_js(drupal_get_path('module','avatarcrop').'/js/jquery.Jcrop.js');
drupal_add_css(drupal_get_path('module','avatarcrop').'/css/jquery.Jcrop.css');
drupal_add_css(drupal_get_path('module','avatarcrop').'/avatarcrop.css');

}

function avatarcrop_menu() {

$items = array();

$items['user/cropimage'] = array(
'title' => t('Crop Image'),
'page callback' => 'drupal_get_form',
'page arguments' => array('cropUserPic'),
'access arguments' => avatarcrop_perm(),
'type' => MENU_CALLBACK
);
$items['user/getimage'] = array(
'title' => t('Upload Image'),
'page callback' => 'drupal_get_form',
'page arguments' => array('avatarcrop_form'),
'access arguments' => avatarcrop_perm(),
'type' => MENU_CALLBACK
);

return $items;
}

function avatarcrop_user($op, &$edit, &$users, $category = NULL){
switch ($op){
case 'view' :
$enablePicture=variable_get('user_pictures','0');
if($enablePicture) {
if($users->picture){
$pictureMsg = t('Change Avatar');
}
else {
$pictureMsg = t('Upload Picture');
}
$base=base_path();
global $user;
$owner=$user->uid;
if($owner==arg(1)) {
$users->content['user_picture']['link_to_crop'] = array(
'#prefix' => '

',
'#suffix' => '

',
'#value' => ''. $pictureMsg .'',
'#weight' => -10,

);
}
}
}
}

/**
* STEP 1 : file upload form
*
* @return unknown
*/
function avatarcrop_form() {
$form = array();
// If this #attribute is not present, upload will fail on submit

$form['#attributes']['enctype'] = 'multipart/form-data';

$form['avatar_crop_title']=array(
'#prefix' => '

',
'#suffix' => '

',
'#value' => t('Choose profile picture.'),
);
$form['file_upload'] = array(
'#title' => t('Upload file'),
'#type' => 'file',
);
$form['submit_upload'] = array(
'#type' => 'submit',
'#value' => 'Upload'
);

$enablePicture=variable_get('user_pictures','0');
if($enablePicture) {
return $form;
}
else {
$form2['user_picture_disable']=array(
'#prefix' => '

',
'#suffix' => '

',
'#value' => t('Please enable user picture first to use Avatar crop.'),

);
return $form2;
}

}
function avatarcrop_form_submit($form, &$form_state) {
$validators = array(
'file_validate_is_image' => array(),
'file_validate_image_resolution' => array('500x500'),
'file_validate_size' => array(500 * 1024),

);
$upload_dir=variable_get('user_picture_path','pictures');
$filepath=file_directory_path();
$dest = $filepath . '/' .$upload_dir;
$file = file_save_upload('file_upload', $validators, $dest);
global $user;
$owner=$user->uid;
$filetype;
$filetype = $file->filemime;
$extension='';
switch ($filetype) {
case 'image/jpeg':
$extension='jpg';
break;
case 'image/png':
$extension='png';
break;
case 'image/gif':
$extension='gif';
break;
}
$dest = variable_get('user_picture_path', 'pictures') .'/picture-'. $owner .'.'. $extension;

if ($file != 0) {

//$dest_path = 'files/upload_directory';
$result = file_move($file, $dest, FILE_EXISTS_REPLACE);
if ($result == 1) {

$_SESSION['filepath']=$file->filepath;
$_SESSION['fid']=$file->fid;
$_SESSION['filetype']=$file->filemime;

drupal_goto('user/cropimage');
}
else {
//Failure
}
}
else {
form_set_error('', t("Failed to upload the file."));
}

}

/**
* STEP 2 : crop the image form
*
* @return unknown
*/
function cropUserPic() {

$form=array();
$filePath = $_SESSION['filepath'];

$enablePicture=variable_get('user_pictures','0');

if($enablePicture==0) {
$_SESSION['filepath']=null;
}

$base=base_path();
if($filePath){
$form['avatar_crop_title']=array(
'#prefix' => '

',
'#suffix' => '

',
'#value' => t('Make a selection on the below image to define the crop area.'),
);
$form['imageview']= array(
'#value' => 'Only local images are allowed.',
);

$form['x1']=array(
'#type' => 'hidden',
);
$form['y1']=array(
'#type' => 'hidden',
);
$form['x2']=array(
'#type' => 'hidden',
);
$form['y2']=array(
'#type' => 'hidden',
);
$form['h']=array(
'#type' => 'hidden',
);
$form['w']=array(
'#type' => 'hidden',
);
$form['cropsubmit'] = array(
'#type' => 'submit',
'#value' => 'Continue',
//'#submit' => array('cropSubmit'),
);

}

return $form;

}

/**
* STEP 3 : tweak the user picture with the crop image
*/
function cropUserPic_validate($form, &$form_state){
$w=$form_state['values']['w'];
$h=$form_state['values']['h'];

if(!$h){
form_set_error('',t('Please crop the image to continue.'));
}

}

function cropUserPic_submit($form, &$form_state)
{

$dimension=variable_get('user_picture_dimensions','100x100');

$widthXheight=split('x',$dimension);

$targ_w = $widthXheight[0];
$targ_h = $widthXheight[1];
$jpeg_quality = 90;

$x=$form_state['values']['x1'];
$y=$form_state['values']['y1'];
$w=$form_state['values']['w'];
$h=$form_state['values']['h'];

$src = $_SESSION['filepath'];
$dot = strrpos($src, '.');
if (!($dot === false))
{
$newsrc = substr($src, 0, $dot) . rand() . substr($src, $dot);
if (rename($src, $newsrc))
{
$src = $newsrc;
}
}
$filetype=$_SESSION['filetype'];

$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
switch ($filetype) {
case 'image/jpeg':
$img_r = imagecreatefromjpeg($src);
imagecopyresampled($dst_r,$img_r,0,0,$x,$y,$targ_w,$targ_h,$w,$h);
imagejpeg($dst_r,$src,$jpeg_quality);
break;
case 'image/png':
$img_r = imagecreatefrompng($src);
imagecopyresampled($dst_r,$img_r,0,0,$x,$y,$targ_w,$targ_h,$w,$h);
imagepng($dst_r,$src);
break;
case 'image/gif':
$img_r = imagecreatefromgif($src);
imagecopyresampled($dst_r,$img_r,0,0,$x,$y,$targ_w,$targ_h,$w,$h);
imagegif($dst_r,$src);
break;
}

global $user;
db_query("update {users} set picture='%s' where uid=%d",$src,$user->uid);
///cleaning the sessions
$_SESSION['filepath']=NULL;
$_SESSION['fid']=NULL;
$_SESSION['filetype']=NULL;

drupal_goto('user/'.$user->uid.'/edit');

}

/**
*
* hide the picture fieldset
*
* @param $form
* @param $form_state
* @param $form_id
*/

function avatarcrop_form_alter(&$form, &$form_state, $form_id) {

if ($form_id == 'user_profile_form') {
$base=base_path();
$description_upload = $form['picture']['picture_upload']['#description'];
$form['picture']['picture_upload'] = array(

'#value' => ''. t('Upload picture') .'',
);
$form['picture']['#description'] = $description_upload;

}
}

Babalu’s picture

patch works great too
please integrate in module :)

pixelsweatshop’s picture

I swapped out the code for the one you have provided and the "Upload Picture" link in the user account doesn't work.

adeel.iqbal’s picture

@nigel.waters: try patch given in #22

adeel.iqbal’s picture

Assigned: Unassigned » adeel.iqbal
Status: Active » Fixed

New version of module is available now. please upgrade to or use the newer version.

adeel.iqbal’s picture

Status: Fixed » Closed (fixed)

newer versions available that work fine.