Add 'Watermark' to images with php _code - php

I have a website where users may upload images...
I need to add my logo (watermark) to the images every single time to uploaded.
How can I do so?
Anybody have a good tutorial, article or example for this? Or know of any function in php which I would need to find the position of the watermark?
<?php
if(houzez_edit_property()) {
$property_images = get_post_meta( $property_data->ID, 'fave_property_images', false );
$featured_image_id = get_post_thumbnail_id( $property_data->ID );
$property_images[] = $featured_image_id;
$property_images = array_unique($property_images);
if (!empty($property_images[0])) {
foreach ($property_images as $prop_image_id) {
$is_featured_image = ($featured_image_id == $prop_image_id);
$featured_icon = ($is_featured_image) ? 'text-success' : '';
$img_available = wp_get_attachment_image($prop_image_id, 'thumbnail');
if (!empty($img_available)) {
echo '<div class="col-md-3 col-sm-4 col-6 property-thumb">';
echo wp_get_attachment_image($prop_image_id, 'houzez-item-image-1', false, array('class' => 'img-fluid'));
echo '<div class="upload-gallery-thumb-buttons">';
echo '<button class="icon icon-fav icon-featured" data-property-id="' . intval($property_data->ID) . '" data-attachment-id="' . intval($prop_image_id) . '"><i class="houzez-icon icon-rating-star full-star '.esc_attr($featured_icon).'"></i></button>';
echo '<button class="icon icon-delete" data-property-id="' . intval($property_data->ID) . '" data-attachment-id="' . intval($prop_image_id) . '"><span class="btn-loader houzez-loader-js"></span><i class="houzez-icon icon-remove-circle"></i></button>';
echo '</div>';
echo '<input type="hidden" class="propperty-image-id" name="propperty_image_ids[]" value="' . intval($prop_image_id) . '"/>';
if ($is_featured_image) {
echo '<input type="hidden" class="featured_image_id" name="featured_image_id" value="' . intval($prop_image_id) . '">';
}
echo '</div>';
}
}
}
}
?>

Use PHP GD Library. You can open saved image file, write text or overlay watermark image and save image again.

Related

jQuery Popup not working with output from PHP

I'm looking to correct this script form popup each image with is corresponding texts. Actually it popup with all text in MySQL. Why isn't it showing the respective text for each image?
<?php
while ( $alaune = mysqli_fetch_assoc( $resultat6 ) ) {
if ( ! empty( $alaune ) ) {
echo '<div class="single_iteam"><img alt="" src="changements/une/images/' . $alaune["alaunePic"] . '" class="alaunePic">';
echo '<div class="slider_article">';
echo '<h2><a class="slider_tittle" href="#">' . $alaune["alauneTitre"] . '</a></h2>';
echo '<p class="alaunetexte truncate">' . $alaune["alauneTexte"] . '</p>';
?>
Lire la suite...
<?php echo '</div>';
echo '</div>';
}
}
echo '</div><div class="modal" id="modal-name"><div class="modal-sandbox"></div><div class="modal-box"><div class="modal-header"><div class="close-modal">✖</div>';
foreach ( $resultat6 as $alaune ) {
echo '<h1>' . $alaune["alauneTitre"] . '</h1><p>' . $alaune["alauneTexte"] . '</p>';
}
echo '</div>';
echo '<div class="modal-body"><br /><button class="close-modal"> Fermer </button></div></div></div>';
?>
Please have a look. Best regards.
Your second loop cannot iterate through the mysqli_result object. You need either to iterate again through results using mysqli_fetch_assoc or a better solution is to temporary store output of all modals in the array during while iteration and then after while loop, output it. Also, use integer variable to increment it during while loop and assign it as a suffix to modal id, that would differentiate modal for each record:
<?php
$modals = [];
$key = 1;
while ( $alaune = mysqli_fetch_assoc( $resultat6 ) ) {
if ( ! empty( $alaune ) ) {
echo '<div class="single_iteam"><img alt="" src="changements/une/images/' . $alaune["alaunePic"] . '" class="alaunePic">';
echo '<div class="slider_article">';
echo '<h2><a class="slider_tittle" href="#">' . $alaune["alauneTitre"] . '</a></h2>';
echo '<p class="alaunetexte truncate">' . $alaune["alauneTexte"] . '</p>';
?>
Lire la suite...
<?php echo '</div>';
echo '</div>';
$tempModal = '<div class="modal" id="modal-name-' . $key . '"><div class="modal-sandbox"></div><div class="modal-box"><div class="modal-header"><div class="close-modal">✖</div>' .
'<h1>' . $alaune["alauneTitre"] . '</h1><p>' . $alaune["alauneTexte"] . '</p></div>' .
'<div class="modal-body"><br /><button class="close-modal"> Fermer </button></div></div></div>';
$modals[] = $tempModal;
$key++;
}
}
echo '</div>';
foreach($modals as $modal){
echo $modal;
}
?>

wordpress php can't combine string with code

add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);
function my_wp_nav_menu_objects( $items, $args ) {
// loop
foreach( $items as &$item ) {
// vars
$image = get_field('menu_item_image', $item);
// append image
if( $image ) {
$item->title .= '<img class="ttl" src="' . <?php echo
$image['url']; ?> . '" alt="' . <?php echo $image['alt']; ?> . '" />';
}
}
// return
return $items;
}
What am I doing wrong? New to PHP and WordPress functions. The problem seems to be in the append image section.
replace this:
$item->title .= '<img class="ttl" src="' . <?php echo
$image['url']; ?> . '" alt="' . <?php echo $image['alt']; ?> . '" />';
for this
$item->title .= '<img class="ttl" src="' .$image['url']. '" alt="' . $image['alt'] . '" />';
you cannot use this <?php echo $image['alt']; ?> inside echo '...'
Reference: http://php.net/manual/en/function.echo.php

Displaying an image via acf in the theme header

I am using AFC Pro and created an options pafe so tjhat the user can upload a new header logo whenever he wants to.
The ACF field is called "headerlogo".
What I want now is that the Logo gets replaced by my theme automatically.
My Variables are:
$headerlogo = wp_get_attachment_image_src(get_field('headerlogo', 'option'), 'full');
$default_logo = '<img src="'echo .$headerlogo[0].'" alt="SITE Logo">';
they get called in:
echo '<a href="'. esc_url( home_url( '/' ) ) .'">
' . $default_logo . '
</a>';
But the Output is:
<a href="http://www.xxx.de/">
<img src="" alt="SITELogo">
</a>
What am I doing wrong here?
Thank in advance.
This should work:
<?php
$headerlogo = get_field('headerlogo');
if( !empty($headerlogo) ):
$default_logo = '<img src="'. $headerlogo['url'] . '" alt="' . $headerlogo['alt'] . '" />';
endif;
echo '' . $default_logo . '';
?>

Returning Art Canvas name and Size inside a query

Hi Guys I need some help here on a project that I am currently working on this is the index function on a controller in my Web App that I have made for a client that everything is working fine but I need to return the title and size of the canvas with the image here is my controller code
public function index(){
$query_result = $this->Art_m->get_art();
error_log(count($query_result));
$canvas = '';
$counter = 0;
foreach($query_result as $row) {
$title = $row['canvas_name'];
$image = $row['canvas_image'];
$size = $row['canvas_size'];
error_log($title . $image . $size);
if($counter == 0){
$canvas .= '<div class="item">
<a rel="prettyPhoto" class="thumbnail" href="' . base_url() . 'data/uploads/canvases/' . $image . '" alt="' . $title . '">
<img src="' . base_url() . 'data/uploads/canvases/' . $image . '" alt="' . $title . '"/>
</a>
</div>';
} else {
$canvas .= '<div class="item">
<a rel="prettyPhoto" class="thumbnail" href="' . base_url() . 'data/uploads/canvases/' . $image . '" alt="' . $title . '">
<img src="' . base_url() . 'data/uploads/canvases/' . $image . '" alt="' . $title . '"/>
</a>
</div>';
}
$counter++;
}
$data['canvas'] = $canvas;
$data['title'] = 'Ali Cockburn Abstract Art';
$data['art'] = $this->Art_m->get_art();
$data['content'] = 'art_view';
$this->load->view('templates/site/template',$data);
}
The code works perfectly, but how do I echo out the $title and $size above the <a> tag inside of a <p> tag? Can someone please assist?

conditional logic in the header.php

So I am using Wordpress and I have to have a specific logo on a specific page. From research I have to use conditional logic to swap the existing logo with another depending on the current page. Everything I have tried seems to just break the theme.. Any help on guiding me in the correct direction? So basically every page except page_id=79 would have the same logo in the header.
<a id="logo" href="<?php echo home_url(); ?>">
<?php
if(!empty($options['use-logo'])) {
$default_logo_id = (!empty($options['retina-logo'])) ? 'id="default-logo"' : null;
echo '<img '.$default_logo_id.' alt="'. get_bloginfo('name') .'" src="' . $options['logo'] . '" />';
if(!empty($options['retina-logo'])) echo '<img id="retina-logo" alt="'. get_bloginfo('name') .'" src="' . $options['retina-logo'] . '" />';
} else { echo get_bloginfo('name'); }
?>
</a>
<?php if ( is_page(79) ) { ?>
What to displayed on page 79.
<?php } else { ?>
What will be displayed everywhere else.
<?php } ?>
This should work.
Try using get_queried_object_id();
<a id="logo" href="<?php echo home_url(); ?>">
<?php
if(!empty($options['use-logo']) && get_queried_object_id() != 79) {
$default_logo_id = (!empty($options['retina-logo'])) ? 'id="default-logo"' : null;
echo '<img '.$default_logo_id.' alt="'. get_bloginfo('name') .'" src="' . $options['logo'] . '" />';
if(!empty($options['retina-logo'])) echo '<img id="retina-logo" alt="'. get_bloginfo('name') .'" src="' . $options['retina-logo'] . '" />';
} else { echo get_bloginfo('name'); }
?>
</a>
The url of your logo image is contained within $options['logo']. You should be able to modify this in the admin section of your WordPress installation (try looking in "Appearance -> Header").

Categories