Hello! There is a task - processing the downloaded image. The photo should be checked so that it can be superimposed text. I did not think that this would be problematic. Because site on Codeignite, I immediately decided to use image_lib: just take a picture, in fact, just black and apply it as a watermark, setting opacity = 50 at the same time. But it was not there ... After suffering with experiments, I realized that is not so simple. When you try to apply a solid watermark, nothing has changed (

$config['source_image'] = $img_path; $config['create_thumb'] = FALSE; $config['wm_type'] = 'overlay'; $config['wm_opacity'] = 50; $config['wm_overlay_path'] = $watermark_file; $this->image_lib->initialize($config); $this->image_lib->watermark(); 

Tell me, please, how to implement such a chip ...

    2 answers 2

    If we proceed from this documentation, then evenly filled with a black file for watermark will not give you anything, because The following parameters exist: wm_x_transp and wm_x_transp with a default value of 4

    If your watermark image is “transparent”. This setting (along with the next) This is a “X” and “Y” coordinate of the pixel of the pixel (measured from the upper left).

    Try setting them to 0, maybe the module will not then consider your black color as the color of transparency.

    UPDATE
    In the library from CodeIgniter, there is a definition and selection of the blending method:

      // Set RGB values for text and shadow $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); $alpha = ($rgba & 0x7F000000) >> 24; // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency if ($alpha > 0) { // copy the image directly, the image's alpha transparency being the sole determinant of blending imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height); } else { // set our RGB value from above to be transparent and merge the images with the specified opacity imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); } 

    Based on this code, the only solution is likely to be:

    1. Create a PNG or GIF filled with black color of a large size (say 500x500)
    2. Upper left pixel to make a little bit lighter
    3. wm_x_transp and wm_y_transp to 1
    • Thank you very much, everything worked out! - XomiaK

    Made a picture of the desired size, white. In the upper right corner I made a darker square (with a 1px square it did not work. I did a little more and it worked).

    Handler:

     $watermark_file = 'img/white.png'; // наша картинка белого цвета $config['source_image'] = '.' . $image; // картинка, которую обрабатываем $config['create_thumb'] = FALSE; $config['wm_type'] = 'overlay'; $config['wm_opacity'] = 60; $config['wm_overlay_path'] = $watermark_file; $config['wm_x_transp'] = 1; $config['wm_y_transp'] = 1; $CI->image_lib->initialize($config); $CI->image_lib->watermark();