PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 19, 2022

[FIXED] How to store data in an image with php?

 September 19, 2022     image-processing, imagick, php     No comments   

Issue

I have tried to use the imagick library to create two functions like this:

function storeCoordinatesImage($img_path, $coordinates){
    $im = new imagick($img_path);
    $im->setImageProperty("coords", $coordinates);
    $im->writeImage($img_path);
}

function getCoordinatesImage($img_path){
    $im = new imagick($img_path);
    return $im->getImageProperty("coords");
}

If I run:

if(!storeCoordinatesImage("I.jpg", "hi")) echo "fal";
echo getCoordinatesImage("I.jpg");

Nothing is returned.

But if I run:

$im = new imagick($img_path);
$im->setImageProperty("coords", "hello");
echo $im->getImageProperty("coords");

it returns "hello".

So it must be some issue with writing to the image? Although none of these functions are returning false. (i.e they are all working)


Solution

As Ben mentioned this is not possible. Instead you can add a "comment":

function storeCommentImage($img_path, $coordinates){
    $im = new imagick($img_path);
    $im->commentImage($coordinates);
    return $im->writeImage($img_path);
}

function getCommentImage($img_path){
    $im = new imagick($img_path);
    return $im->getImageProperty("comment");
}


Answered By - maxisme
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing