Possible to replace thin white border by bleeding out edge?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
RandomRandom

Possible to replace thin white border by bleeding out edge?

Post by RandomRandom »

Can someone with more expertise than myself please tell me how i can do this:

I have a bunch of album cover jpegs for all of my music. They are all the same square 300x300 dimension. The problem is that a good number of them have white edges (some have one edge, some two, etc.) that show up when viewing them on a dark background. It is as though the image was not quite cropped enough originally. In general, the white borders are only a few pixels wide. Is there some way to bleed out the edge to remove these white borders. I would like to keep the dimensions of the original jpegs. I would like to be able to process them all in a batch file. I have very limited programming experience so any help would be appreciated.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Possible to replace thin white border by bleeding out edge?

Post by Bonzo »

Post an image !

-trim may work.
RandomRandom

Re: Possible to replace thin white border by bleeding out edge?

Post by RandomRandom »

Just imagine any sort of square image with a one or two pixel wide white border around one, two, three or four of the image's edges. I want to somehow batch process a number of such images to remove these white edges and replace them "intelligently" with their neighbor's colour. Basically I just want some way to remove the white edges and keep the file image the same size dimensionally.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Possible to replace thin white border by bleeding out edge?

Post by anthony »

An example would be better. It will let us know how much varience there is in the colors, as well as if the scan is rotated slightly. things like that.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible to replace thin white border by bleeding out edge?

Post by fmw42 »

I just posted a new script, autotrim, to http://www.fmwconcepts.com/imagemagick/index.php which will automatically trim out any border pixels. But it will make the image smaller by the amount that is trimmed. If this is a small amount, just a few pixels out of 300 pixels, you can post-process the result to enlarge the image back to its original size of 300x300 by using

convert image_from_autotrim -resize 300x300! image_back_to_original_size

This will distort the image aspect ratio slightly, but if the trim is only a few pixels, you probably won't notice it.

So you need to make a script, that calls my script autotrim as one line of the script and then add another line of the script using the command line above.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Possible to replace thin white border by bleeding out edge?

Post by Bonzo »

I finaly got the code to work with php after a few tests :?

Code: Select all

<?php
exec("FULL PATH TO/autotrim.sh zelda3_border2w.png fred.png 2>&1", $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
?>
NOTE:
I had to use the full path to the autotrim.sh script.
I had to change the permissions on autotrim.sh to 777

Does this sound the correct way to do this ?

I returned some errors but it seems to have worked OK:
Array
(
[0] => /autotrim.sh: line 271: bc: command not found
[1] => /autotrim.sh: line 272: bc: command not found
[2] => /autotrim.sh: line 271: bc: command not found
[3] => /autotrim.sh: line 272: bc: command not found
)
1

Line 271 - midwidth=`echo "scale=0; $width / 2" | bc`
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible to replace thin white border by bleeding out edge?

Post by fmw42 »

Hello Anthony,

My scripts were designed for command line use under the bash shell. I do not know about using them from PHP. I have no experience with the PHP API.

Giving the full path and adding .sh may be needed for use with PHP. My script file itself does not have .sh appended, but that may be needed the way you are using it. Resetting permission is a good idea, anyway and may require different permission running under bash than under the PHP API

bc is a shell function to do math calculations. It is needed in several places. The error you are getting with it is at a place where it is calculating the half-way point along the edge, but bc is used in many other places in this and many of my other scripts.

You may need to ask others who are more experts than I about using shell commands such as bc within PHP API. I would certainly like to understand this better, now that you raise the issue. Hopefully someone else will respond here about this issue.

In looking at your example page (sent separately) I note an error in your usage:

exec("/home/barnett/public_html/TESTS/autotrim.sh -a0 image3s_rot45.png fred2.png 2>&1", $array1); echo "


You need to separate the parameter value from the argument, so that -a0 should be -a 0

exec("/home/barnett/public_html/TESTS/autotrim.sh -a 0 image3s_rot45.png fred2.png 2>&1", $array1); echo "

This is why you are getting "TOO MANY ARGUMENTS" error.


Hope this helps.


Fred
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Possible to replace thin white border by bleeding out edge?

Post by anthony »

Bonzo, you should be able to use premissions 755 so only you can write to the script.
It should still run fine for ANYONE using it. It may be that the PHP on your system runs as a different user to you (as a security measure) which is why you needed a permission change.

I am not certain why you are getting 'bc' not found. 'bc' is pretty well a standard utility on all UNIX-like computers, and is a command line calculator. It may be just another command that is not on the default PHP command path. This command path situation
is bad.

One solution may be to modify the script to set PATH is it is not set right, or have it try to locate a 'bc' command. On my linux system 'bc' is located in ' /usr/bin/bc'. I believe if PATH environment is unset the systen defaults to just '/bin'.

fmw42, The .sh in this case is only an identifier of what type of script it is for things like GUI file managers. It is not important. A similar extension exists for perl (.pl).

Under UNIX-like systems the fact that the command has execution flags set (and no suffix to the contrary) is usually a good enough indicator that it is a directly executable program of some type. The "file" command can tell you what type of executable, if you need to know.

Unfortunately, windows machines were basied on brain dead DOS, and that system liked to define everything as Executable, and as a consequence, when window systems are involved the executable flag method becomes rather useless. This is why I included the 'no suffix to the contrary' in the UNIX definition as a lot of image, video, audio, and other thypes of data files originate or pass through windows machines, causing the executable flag to be set, much to the annoyance of UNIX users, when they find they are trying to execute a JPEG image!

There is a way to allow shell options to accept both "-a 0" and "-a0".
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Possible to replace thin white border by bleeding out edge?

Post by Bonzo »

Thanks for the information; I spoke to the IT guy at work and he said to try "which bc" to find the path to bc. That didn't return anything so I assumed that bc was not installed. I emailed my host and they installed it straight away and everything seems to be OK now :D

I will give some of the other examples a go later with the notes above.

NOTE: The IT guy at work said I may have been able to install the bc binarys ( although I could not find them ) and use the path to those in the code. I did not need to try that so I do not know if it would have worked or not.
Post Reply