Image convert to Negative

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
abayputra2000
Posts: 3
Joined: 2020-01-13T09:40:11-07:00
Authentication code: 1152

Image convert to Negative

Post by abayputra2000 »

Hi,

I have a problem where some of the images when converting using IM it turns as negative. Below are the commands that i use in my Java code to convert images. (both original image and as well as effected images are attached). But this is not happening with all the images hardly 1 or 2 for every 100 images. I could think that image could be incompatible for the conversion.
Please help me in this am very new to IM. (have tried this with IM7, IM6.9.9 and IM6.9.1 )


[try {
im4jpath = Config.getConfig().getString(
ConfigConstants.COMMON_IMAGEMAGIC_HOME);
iccFileName = Config.getConfig().getString(
ConfigConstants.PUBLISH_RGB_PROFILE_NAME);
operationProfile = System.getenv("TEAMS_HOME") + File.separator
+ "servers" + File.separator + "profiles" + File.separator
+ iccFileName;
ProcessStarter.setGlobalSearchPath(im4jpath);

cmd = new ImageMagickCmd("imconvert");
cmd.setSearchPath(im4jpath);

destDir = new File(destDirPath);
if (!destDir.isDirectory()) {
destDir.mkdirs();
}

actualFileExtn = FilenameUtils.getExtension(sourceFilePath);

if ("PSD".equalsIgnoreCase(actualFileExtn)) {
sourceFilePath = sourceFilePath + "[0]";
}
target4Image = destDirPath + File.separator + newName + ".png";
if (actualFileExtn != null
&& ( "eps".equalsIgnoreCase(actualFileExtn) || "jpg".equalsIgnoreCase(actualFileExtn))){
target4Image = destDirPath + File.separator + newName + ".jpg";
}


operation = new IMOperation();
if (actualFileExtn != null
&& "eps".equalsIgnoreCase(actualFileExtn)) {
operation.density(300);
}
imageInfo = ImageUtil.getInstance().getAllImageInfo(sourceFilePath);
int originalWidth = imageInfo.getWidth();
int originalHeight = imageInfo.getHeight();
int newWidth = originalWidth;
int newHeight = originalHeight;
final int MAX_WIDTH = 1532;
final int MAX_HEIGHT = 1382;
double aspectRatio = (double) originalWidth / originalHeight;
log.debug(String.format("image original measurement:.......width.........%s.........height..........%s........"
+ "aspectRatio........%s", originalWidth, originalHeight, aspectRatio) );
if ( (aspectRatio >= 1) && (newWidth > MAX_WIDTH) ) {
newWidth = MAX_WIDTH;
newHeight = (int) Math.round(newWidth / aspectRatio);
if (newHeight > MAX_HEIGHT) {
newHeight = MAX_HEIGHT;
newWidth = (int) Math.round (newHeight * aspectRatio);
}
}
if ( (aspectRatio < 1) && (newHeight > MAX_HEIGHT) ) {
newHeight = MAX_HEIGHT;
newWidth = (int) Math.round(newHeight * aspectRatio);
if (newWidth > MAX_WIDTH) {
newWidth = MAX_WIDTH;
newHeight = (int) Math.round (newWidth / aspectRatio);
}
}
log.debug(String.format("image new measurments:........width.........%s.........height.........%s",
newWidth, newHeight));
operation.addImage(Operation.IMG_PLACEHOLDER);
operation.units("PixelsPerInch");
operation.thumbnail(newWidth, newHeight);
operation.background("white");
operation.flatten();
operation.profile(operationProfile);

operation.strip();
log.debug("extension......."+actualFileExtn);

operation.addImage(Operation.IMG_PLACEHOLDER);
log.debug("operation......."+operation.toString());
cmd.run(operation, sourceFilePath, target4Image);
} catch (IOException e) {
log.error(getStackTraceAsString(e));
} catch (InterruptedException e) {
log.error(getStackTraceAsString(e));
} catch (IM4JavaException e) {
log.error(getStackTraceAsString(e));
} catch (Exception e) {
log.error(getStackTraceAsString(e));
} finally {
operation.closeOperation();
}

if ("PSD".equalsIgnoreCase(actualFileExtn)
|| "EPS".equalsIgnoreCase(actualFileExtn)) {
new File(target4Image.replace(".jpg", "-0.jpg")).renameTo(new File(
target4Image));
}

return target4Image;[/size]
Last edited by abayputra2000 on 2020-01-29T09:59:56-07:00, edited 1 time in total.

abayputra2000
Posts: 3
Joined: 2020-01-13T09:40:11-07:00
Authentication code: 1152

Re: Image convert to Negative

Post by abayputra2000 »

not able to upload Images here

User avatar
fmw42
Posts: 26292
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image convert to Negative

Post by fmw42 »

This forum does not support direct upload. Please post any images to some free hosting service and put the URLs here

Post Reply