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
Comment #1
magoo commentedbtw: the String should be localisable t().
Comment #2
Babalu commentedcan you please make a patch that this module works
or type the correct code here
Comment #3
magoo commentedI 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!
Comment #4
mstef commented+1 - does not work at all
oops
Comment #5
mzi commentedjust pushing it up.
changed my way from cck_imagefield to built in user picture and now i would really enjoy this avatarcrop!
Comment #6
ghiley commentedI 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?
Comment #7
v8powerage commentedThis module should be renamed Avatar Crap
Comment #8
betoaveigaDoesn'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.
Comment #9
adeel.iqbal commentedHi,
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
and REPLACE it or CHANGE it to
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:
And Change it to:
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
to this (Remove the comma)
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.
Comment #10
newitt commentedThank 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
Comment #11
adeel.iqbal commentedMy pleasure ;)
Comment #12
newitt commentedI 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?
Comment #13
newitt commentedIt is ok, I found the answer here:
http://drupal.org/node/506360
Comment #14
pixelsweatshop commentedThis 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?
Comment #15
adeel.iqbal commented@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.
Comment #16
Babalu commentedworks great for me with the patches :)
Comment #17
adeel.iqbal commentedThat's good ;)..
Subscribe here if you want these patches to be integrated in the module.
Comment #18
Babalu commentedplease 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
Comment #19
adeel.iqbal commentedTo enable delete option just comment or remove the following line of code from 'function avatarcrop_form_alter(......)' in 'avartcrop.module'.
OR
you can use this new patch instead of the patch given in "#5" .
Comment #20
adeel.iqbal commentedSubscribe here if you want these patches to be integrated in module ;)
Comment #21
Babalu commentedhmm i can't save the attached patch
Comment #22
adeel.iqbal commentedhmmm 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.
Comment #23
gitin commentedthanx 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' => '
',
'#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' => '
);
$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;
}
}
Comment #24
Babalu commentedpatch works great too
please integrate in module :)
Comment #25
pixelsweatshop commentedI swapped out the code for the one you have provided and the "Upload Picture" link in the user account doesn't work.
Comment #26
adeel.iqbal commented@nigel.waters: try patch given in #22
Comment #27
adeel.iqbal commentedNew version of module is available now. please upgrade to or use the newer version.
Comment #28
adeel.iqbal commentednewer versions available that work fine.