Solved

Overlay image or texture over text and png files

Posted on 2016-10-05
5
52 Views
Last Modified: 2016-10-07
Hi,

I'm working on a small project that involves modifying a Wordpress plugin to suit our specific needs.  The code for the plugin is not organized very well (not as well as I have seen other plugins), nor is it documented, and after asking the developer for help (offering to pay) he said that what I needed was not possible.  However, I am a firm believer that anything is possible with good programming!  So please experts, can you tell me if this is possible or not...

Right now, the script allows you to change the color of the text and PNG or SVG images by selecting it and clicking on the color to change it.  Easy enough.  However, I want to be able to not only change the color of the text and the PNG images, but overlay them with a texture or image.  In the backend, you can specify which colors are available to the end user.  I want to be able to also upload textures to be available to the end user as well... at least specify them programmatically somehow.

I thought this would be possible with CSS, but I could not find any examples of it in searching Google.  If there is a code snippet somewhere that demonstrates this that would be great.  Any help is appreciated!
0
Comment
Question by:Carolyn
5 Comments
 
LVL 51

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
Comment Utility
You have two options.
1. You can use html and css
Method 1
   container with style position: relative
   two images in the container with position: absolute;
   z-index on the image stacks them
   Top image is PNG - bottom can be anything
   You get an overlay effect

Method 2
  Container has image 1 as a background
  img 2 is contained in the container

2. Backend merge of png files
    Using GD2 library
Example from here imagecreatefrompng
<?php
// Create image instances
$dest = imagecreatefromgif('php.gif');
$src = imagecreatefromgif('php.gif');

// Copy and merge
imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75);

// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);

imagedestroy($dest);
imagedestroy($src);
?>

Open in new window

Additional references
imagecopymerge
imagepng
2
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 250 total points
Comment Utility
A note on the above. The images used in the sample are gifs. If you use PNG's you will need this function
function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){
  // creating a cut resource
  $cut = imagecreatetruecolor($src_w, $src_h);

  // copying relevant section from background to the cut resource
  imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
   
  // copying relevant section from watermark to the cut resource
  imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
   
  // insert cut resource to destination image
  imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
}

Open in new window

Call this instead of imagecopymerge.

Here is a working sample showing all three methods
1
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 125 total points
Comment Utility
If you want to do this with PHP, with respect to "texture" you may be able to achieve what you want (depending on the texture) by applying some kind of ImageFilter() algorithm.  There are some basic examples in this article (see Working with Transparent Pixels).  

Many of the PHP GD2 library functions include the ability to work with an alpha channel for transparency support, eg: ImageColorAllocateAlpha().  We have an article with an example of its use to add a semi-transparent watermark.  Look for "demo/watermark_hotlinked_image.php" in the last code snippet.
0
 
LVL 33

Assisted Solution

by:Slick812
Slick812 earned 125 total points
Comment Utility
greetings Carolyn, , , I have read what you want to do, and you have several things that are dependent on one another as -
    "want to be able to also upload textures"
    "have images and overlay them with a texture or image"
    "specify them programmatically"

AND, you say you need to alter an existing WP plug-in, that is used to -
    "add text to an image"
    "change the color of the text"

Although I do feel that this can be done, I do not see enough information , especially about the plug-in , to know what the final "Display" (text and images I guess) , may look like for what you need, much less how or what to do to get that result. It would be helpful if the "Code" work for the plug-in was available, and some image or description of the placement and the "Effect" (layered or blending ) of what you call - "overlay them with a texture".
0
 

Author Closing Comment

by:Carolyn
Comment Utility
Thank you all for the snippets and encouragement here.  I've been browsing the code looking for the right spot to test these functions.  But it is so badly organized that I've had to go through it file by file (the plugin installs in the root of Wordpress!)  So as soon as I get a grasp on the authors "structure" I can dig in.  So I'll definitely post a new question once I get to it.

The author has made developer "add-on" documentation as well, but it's very vague and his/her first language is not English, so communicating is not working and I'm going to do my best to figure it out.

Thanks again!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now