Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2005-03-27 21:42:00

oranv
New Member
Registered: 2005-01-09
Posts: 6
Website

Re: Admin plugin: glx_admin_image_resize

Good plugin, a very useful one indeed. Made posting photos to the site as simple as picking what to upload because it made resizing photos so easy.

I have a question regarding the plugin. When an image is already uploaded, and I want to resize the image or change the thumbnail from a rectangle to a square, it won’t change it for me. I’m using the latest version of txp and plugin.

Thanks!

Last edited by oranv (2005-03-27 21:55:46)

Offline

#14 2005-03-27 23:22:01

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: Admin plugin: glx_admin_image_resize

osei, harryv,

seen this: http://forum.textpattern.com/viewtopic.php?id=6385

Offline

#15 2005-03-28 08:08:56

osei
Plugin Author
From: Stockholm, Sweden
Registered: 2004-07-01
Posts: 178
Website

Re: Admin plugin: glx_admin_image_resize

oranv, are you using the checkbox and then reupload the big image again? i know this is a little backward, but right now that is the only way to go.


Johan Nilsson

Offline

#16 2005-03-29 02:38:00

ZiQ
Member
Registered: 2005-03-12
Posts: 10
Website

Re: Admin plugin: glx_admin_image_resize

Hi Johan .. I write a little mod for ur pluging… Ihope u like it :)

//Mod by ZiQ

if (@txpinterface == ‘admin’) { register_callback(“glx_image_resize”, “image”); register_callback(“glx_image_edit_opts”, “image”, “thumbnail_insert”); register_callback(“glx_image_edit_opts”, “image”, “image_replace”); register_callback(“glx_image_edit_opts”, “image”, “image_edit”);

}

function IsPercent($x) {

if (is_numeric ($x )) { $tmp = intval($x); if ($tmp >=10 && $tmp <=100) return true; } return false; }

function glx_image_resize($event, $step) { global $path_to_site;

$do_resize_thumb = ps(“id”) ? ps(“doResize_thumb”) : 1; $do_resize_large = ps(“id”) ? ps(“doResize_large”) : 0;

$square_image = ps(“square”) ? ps(“square”) : 0; $largest_side_thumb = ps(“thumbSize”) ? ps(“thumbSize”) : 100; $largest_side_large = ps(“largeSize”) ? ps(“largeSize”) : 500;

$image_id = ps(“id”) ? ps(“id”) : mysql_insert_id();

$quality_thumb = IsPercent(ps(“thumbQua”)) ? intval(ps(“thumbQua”)): 90; $quality_large = IsPercent(ps(“largeQua”)) ? intval(ps(“largeQua”)): 80;

$source = IMPATH.$image_id.’.jpg’;

if (file_exists($source) && ($do_resize_thumb== 1 || $do_resize_large== 1)) {

$size = getimagesize($source);

$x = $size0; $y = $size1;

if ($x > $y) { $max = $x; $min = $y; } if ($x <= $y) { $max = $y; $min = $x; }

if ($do_resize_thumb== 1) { // thumb $rate_thumb = $max/$largest_side_thumb; $final_x_thumb = $x/$rate_thumb; $final_y_thumb = $y/$rate_thumb; // create thumb if ($square_image == 1) { $resize_thumb = imagecreatetruecolor($largest_side_thumb, $largest_side_thumb); $im_thumb = imagecreatefromjpeg($source); imagecopyresampled($resize_thumb, $im_thumb, 0, 0, 0, 0, $largest_side_thumb, $largest_side_thumb, $largest_side_thumb * 1.5, $largest_side_thumb * 1.5); $source_thumb = IMPATH.$image_id.‘t.jpg’; imagejpeg($resize_thumb,$source_thumb, $quality_thumb); imagedestroy($resize_thumb); } else { $resize_thumb = imagecreatetruecolor($final_x_thumb, $final_y_thumb); $im_thumb = imagecreatefromjpeg($source); imagecopyresampled($resize_thumb, $im_thumb, 0, 0, 0, 0, $final_x_thumb, $final_y_thumb, $x, $y); $source_thumb = IMPATH.$image_id.‘t.jpg’; imagejpeg($resize_thumb,$source_thumb, $quality_thumb); imagedestroy($resize_thumb); } $thumb = true; safe_update(‘txp_image’,“thumbnail=’$thumb’”,“id=’$image_id’”); }

if ($do_resize_large== 1) { // large $rate_large = $max/$largest_side_large; $final_x_large = $x/$rate_large; $final_y_large = $y/$rate_large;

// create large if ($x > $final_x_large ) { $resize_large = imagecreatetruecolor($final_x_large, $final_y_large); $im_large = imagecreatefromjpeg($source); imagecopyresampled($resize_large, $im_large, 0, 0, 0, 0, $final_x_large, $final_y_large, $x, $y); imagejpeg($resize_large,$source, $quality_large); imagedestroy($resize_large); } // get size from large $size = getimagesize($source); safe_update(‘txp_image’,“w=’”.$size0.”’,h=’”.$size1.”’”,“id=’$image_id’”);

}

// send user to the image edit view header(“Location: index.php?event=image&step=image_edit&id=”.$image_id); }

}

function glx_image_edit_opts($event, $step) {

// check if glx_admin css is found, if not found create it $rs = safe_row(“name”, “txp_css”, “name=‘glx_admin_image_resize’ limit 1”); if (!$rs) { $css = “bGFiZWwuaW5saW5lIHsNCgltYXJnaW46IDVweDsJDQp9CQ0KDQpsYWJlbC5ibG9jayB7DQoJbWFyZ2luOiA1cHggNXB4IDAgMDsJDQoJZGlzcGxheTogYmxvY2s7DQp9”; safe_insert(“txp_css”, “name=‘glx_admin_image_resize’, css=’$css’”); }

echo <<<EOF
<script language=“JavaScript” type=“text/javascript”>
<!—
window.onload = function() {

// add some new css rules loadCSS(‘css.php?n=glx_admin_image_resize’);

// checkbox doResizedo_large var inputDoResize_large = document.createElement(‘input’); inputDoResize_large.setAttribute(‘name’,‘doResize_large’); inputDoResize_large.setAttribute(‘id’,‘doResize_large’); inputDoResize_large.setAttribute(‘type’,‘checkbox’); inputDoResize_large.setAttribute(‘value’,‘1’); inputDoResize_large.checked = false; var labelDoResize_large = createLabel(‘doResize_large’, ‘Resize Image’, ‘inline’); var pDoResize_large = document.createElement(‘p’); pDoResize_large.appendChild(inputDoResize_large); pDoResize_large.appendChild(labelDoResize_large);

// checkbox doResizedo_resize_thumb var inputDoResize_thumb = document.createElement(‘input’); inputDoResize_thumb.setAttribute(‘name’,‘doResize_thumb’); inputDoResize_thumb.setAttribute(‘id’,‘doResize_thumb’); inputDoResize_thumb.setAttribute(‘type’,‘checkbox’); inputDoResize_thumb.setAttribute(‘value’,‘1’); inputDoResize_thumb.checked = true; var labelDoResize_thumb = createLabel(‘doResize_thumb’, ‘Create thumbnail’, ‘inline’); var pDoResize_thumb = document.createElement(‘p’); pDoResize_thumb.appendChild(inputDoResize_thumb); pDoResize_thumb.appendChild(labelDoResize_thumb);

// checkBox sqareImage var inputSquare = document.createElement(‘input’); inputSquare.setAttribute(‘name’,‘square’); inputSquare.setAttribute(‘id’,‘square’); inputSquare.setAttribute(‘type’,‘checkbox’); inputSquare.setAttribute(‘value’,‘1’); inputSquare.setAttribute(‘style’,‘margin-left:40px;’); inputSquare.checked = false; var labelSquare = createLabel(‘square’, ‘Square thumbnail’, ‘inline’); var pSquare = document.createElement(‘p’); pSquare.appendChild(inputSquare); pSquare.appendChild(labelSquare);

// input thumbSize var newInputThumbSize = createInput(‘thumbSize’, ‘thumbSize’, ‘100’); var newLabelThumbSize = createLabel(‘thumbSize’, ‘Thumbsize (px)’, ‘block’); var newPThumb = document.createElement(‘p’); newPThumb.appendChild(newLabelThumbSize); newPThumb.appendChild(newInputThumbSize);

// input largeSize var newInputLargeSize = createInput(‘largeSize’, ‘largeSize’, ‘500’); var newLabelLargeSize = createLabel(‘largeSize’, ‘Largesize (px)’, ‘block’); var newPLarge = document.createElement(‘p’); newPLarge.appendChild(newLabelLargeSize); newPLarge.appendChild(newInputLargeSize);

// input quality var newInputQua_Thumb = createInput(‘thumbQua’, ‘thumbQua’, ‘90’); var newLabelQua_Thumb = createLabel(‘thumbLabelQua’, ‘Quality Thumb (10-100)’, ‘block’); var newPQua_Thumb = document.createElement(‘p’); newPQua_Thumb.appendChild(newLabelQua_Thumb); newPQua_Thumb.appendChild(newInputQua_Thumb);

// input quality var newInputQua_Large = createInput(‘largeQua’, ‘largeQua’, ‘80’); var newLabelQua_Large = createLabel(‘largeLabelQua’, ‘Quality Large Image (10-100)’, ‘block’); var newPQua_Large = document.createElement(‘p’); newPQua_Large.appendChild(newLabelQua_Large); newPQua_Large.appendChild(newInputQua_Large);
//add hidden field

var hstep = document.createElement(‘input’); hstep.setAttribute(‘name’,‘step’); hstep.setAttribute(‘type’,‘hidden’); hstep.setAttribute(‘value’, ‘image_edit’);

var hid = document.createElement(‘input’); hid.setAttribute(‘name’,‘id’); hid.setAttribute(‘type’,‘hidden’); hid.setAttribute(‘value’, document.getElementsByName(‘id’).item(0).value);

var hevent = document.createElement(‘input’); hevent.setAttribute(‘name’,‘event’); hevent.setAttribute(‘type’,‘hidden’); hevent.setAttribute(‘value’, ‘image’);

var hfs = document.createElement(‘input’); hfs.setAttribute(‘name’,‘MAX_FILE_SIZE’); hfs.setAttribute(‘type’,‘hidden’); hfs.setAttribute(‘value’, document.getElementsByName(‘MAX_FILE_SIZE’).item(0).value);

//add submit
var submit = document.createElement(‘input’); submit.setAttribute(‘class’,‘smallerbox’); submit.setAttribute(‘type’,‘submit’); submit.setAttribute(‘value’, ‘Mod’); submit.setAttribute(‘name’, ‘Mod’);
// add form var form = document.createElement(‘form’); form.setAttribute(‘action’,‘index.php’); form.setAttribute(‘method’,‘post’);

//append form

form.appendChild(newPThumb); form.appendChild(newPLarge); form.appendChild(newPQua_Thumb); form.appendChild(newPQua_Large); form.appendChild(pDoResize_large); form.appendChild(pDoResize_thumb); form.appendChild(pSquare); form.appendChild(hid);

form.appendChild(hfs); form.appendChild(hevent); form.appendChild(hstep); form.appendChild(submit);

// get the upload form element var formins = document.getElementsByTagName(‘form’).item(0);

formins.parentNode.insertBefore(form, formins );

//form.appendChild(pDoResize); //form.appendChild(newPThumb); //form.appendChild(newPLarge);
}

function createInput(name, id, value) { var element = document.createElement(‘input’); element.setAttribute(‘name’,name); element.setAttribute(‘id’, id); element.setAttribute(‘value’,value); element.className = ‘edit’;

return element;
}

function createLabel(forElement, text, elementClass) { var labelElement = document.createElement(‘label’); labelElement.setAttribute(‘for’,forElement); labelElement.className = elementClass; var labelTextNode = document.createTextNode(text); labelElement.appendChild(labelTextNode);

return labelElement;
}

function loadCSS(fileName){ var head = document.getElementsByTagName(‘head’).item(0); var styleElement = document.createElement(‘link’); styleElement.setAttribute(‘href’, fileName); styleElement.setAttribute(‘rel’, ‘stylesheet’); styleElement.setAttribute(‘type’, ‘text/css’); head.appendChild(styleElement)
}
—>
</script>
EOF;
}

Offline

#17 2005-03-29 05:58:21

osei
Plugin Author
From: Stockholm, Sweden
Registered: 2004-07-01
Posts: 178
Website

Re: Admin plugin: glx_admin_image_resize

ZiQ I looks like textile have messed up your post, you are welcome to send me an email with it instead. Thanks!


Johan Nilsson

Offline

#18 2005-03-29 14:07:30

ZiQ
Member
Registered: 2005-03-12
Posts: 10
Website

Re: Admin plugin: glx_admin_image_resize

ça va :)

Offline

#19 2005-03-29 23:07:24

osei
Plugin Author
From: Stockholm, Sweden
Registered: 2004-07-01
Posts: 178
Website

Re: Admin plugin: glx_admin_image_resize

Thank you ZiQ, it looks really great, just what i had i thought for another version really, i just added image rotating to the plugin, i probably release the new version tomorrow, thanks again.

Last edited by osei (2005-03-29 23:08:04)


Johan Nilsson

Offline

#20 2005-03-30 05:36:39

ZiQ
Member
Registered: 2005-03-12
Posts: 10
Website

Re: Admin plugin: glx_admin_image_resize

I wait ur update :P

we can add more feature like a resize into a box for large image

Offline

#21 2005-03-30 09:09:14

osei
Plugin Author
From: Stockholm, Sweden
Registered: 2004-07-01
Posts: 178
Website

Re: Admin plugin: glx_admin_image_resize

New version 0.4b

ZiQ added the following

  • Submit button, no need to upload an image to create thumbnail, square thumbnail or to resize image anymore.
  • Checkbox, if you want to resize the large image
  • Quality input field for thumbnail and large image, but this two fields are commented out right now, personally i think its too cluttered to have them there, but you could comment them out if you want them, the values by default is 90 for thumbs and 80 for large images.

The behavior for the plugin has changed a bit since this version, on upload the plugin will only creates a thumbnail, no resize is now done. When replacing an image it only replace the image, no resize is done or thumbnail is created.

Other updates

  • Image rotating, 180, 90CW, 90CCW, requires php 4.3.0 or greater
  • Plugin renamed to glx_amin_image instead of glx_admin_image_resize
  • Stylesheet renamed to glx_image_admin, delete old one, I also added some new rules to the stylesheet

Note! Since this plugin has been renamed its important to delete the old plugin glx_image_admin_resize before you install this, otherwise ther might be a conflict between them.

Last edited by osei (2005-03-30 09:24:02)


Johan Nilsson

Offline

#22 2005-03-30 09:29:19

osei
Plugin Author
From: Stockholm, Sweden
Registered: 2004-07-01
Posts: 178
Website

Re: Admin plugin: glx_admin_image_resize

This is on my todo list right now

  • add option to resize image on upload and replace

What more is needed? i think is is very important to not have to much options, we dont want to scare “end users” to use this. It should be simple…

A cool thing to have i think is the ability to crop the image, but i think this should be on an own page, so maybe an advanced image edit instead?


Johan Nilsson

Offline

#23 2005-03-30 11:47:56

graumeister
Plugin Author
From: Ban Bang Por, Samui, Thailand
Registered: 2005-01-16
Posts: 167
Website

Re: Admin plugin: glx_admin_image_resize

After installing the following error occurs:

Fatal error: Cannot redeclare glx_image_resize() (previously declared in /home/…/textpattern/lib/txplib_misc.php(304) : eval()’d code:6) in /home/…/textpattern/lib/txplib_misc.php(304) : eval()’d code on line 313

which revision do you use? i am on rev. 243


Samui? Samui! (about the life as farang in thailand)
David’s Neighbour

Offline

#24 2005-03-30 11:48:47

graumeister
Plugin Author
From: Ban Bang Por, Samui, Thailand
Registered: 2005-01-16
Posts: 167
Website

Re: Admin plugin: glx_admin_image_resize

ah, sorry. i did not deleted the old plugin.


Samui? Samui! (about the life as farang in thailand)
David’s Neighbour

Offline

Board footer

Powered by FluxBB