Hi,
I would like to be able to get a derivative (L size, for instance) without watermark, even if a watermark is set. It can be temporary and not go in the cache. I suppose I could:
1) deactivate the watermark
2) ask for L size
3) reactivate the watermark
The problem is that it would have impact on all photos. I just need a single photo without watermark.
How would you do that? (I mean the code)
Offline
Hello, I think your solution has too many drawbacks. Ccopying the relevant code from i.php into your plugin should suffice - that's maximum 30-40 lines ( the rest is init phase, url parsing, watermarking etc ...)
Offline
OK, thank you rvelices. I'm going to try it that way. Duplicating i.php is not really a problem (I did such kind of thing when copying action.php for [extension by plg] Download by Size)
Offline
OK, here comes the code I implemented:
foreach (ImageStdParams::get_all_type_map() as $type => $params) { if ($type == $_GET['size']) { $page['derivative_type'] = $type; $page['derivative_params'] = $params; break; } } if (!isset($page['derivative_type'])) { die('Hacking attempt: unknown size'); } $file = ppcredits_generate_temporary_derivative( $element_info, $page['derivative_type'], $page['derivative_params'] ); $page['delete_temporary_derivative'] = true; // [...] if (isset($page['delete_temporary_derivative']) and $page['delete_temporary_derivative']) { unlink($file); } /** * compared to i.php, this function does not apply the watermark (and only * keep code relevant for ppcredits plugin) */ function ppcredits_generate_temporary_derivative($element_info, $type, $params) { global $conf; $src_path = PHPWG_ROOT_PATH.$element_info['path']; $derivative_filename = $element_info['id'].'-'.$type.'-'.generate_key(20).'.'.get_extension($element_info['path']); $derivative_path = PHPWG_ROOT_PATH.$conf['data_location'].'prepaid_credits/'.$derivative_filename; include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php'); if (!isset($element_info['rotation'])) { $rotation_angle = pwg_image::get_rotation_angle($src_path); } else { $rotation_angle = pwg_image::get_rotation_angle_from_code($element_info['rotation']); } if (!mkgetdir(dirname($derivative_path))) { die("dir create error"); } ignore_user_abort(true); @set_time_limit(0); $image = new pwg_image($src_path); // rotate if (0 != $rotation_angle) { $image->rotate($rotation_angle); } // Crop & scale $o_size = $d_size = array($image->get_width(),$image->get_height()); $params->sizing->compute($o_size, $element_info['coi'], $crop_rect, $scaled_size); if ($crop_rect) { $image->crop( $crop_rect->width(), $crop_rect->height(), $crop_rect->l, $crop_rect->t); } if ($scaled_size) { $image->resize( $scaled_size[0], $scaled_size[1] ); $d_size = $scaled_size; } if ($params->sharpen) { $image->sharpen( $params->sharpen ); } if ($d_size[0]*$d_size[1] < $conf['derivatives_strip_metadata_threshold']) {// strip metadata for small images $image->strip(); } $image->set_compression_quality(ImageStdParams::$quality); $image->write($derivative_path); $image->destroy(); return $derivative_path; }
Thank you for the tip :-)
Offline